@ltd Chào anh! Về bài này hôm trước thầy có chữa cho bọn em, thầy có dùng hàm gì trong string.h để đổi kí tự cuối cùng của dãy \n về kí tự \0, Em chưa hiểu lắm, Anh có thể làm 1 Video về làm việc với file được không, em xem list C++ của anh thiếu mỗi cái đấy!
Dùng hàm gì để đổi ký tự trong C++?
uh huh.
===20===
Trong C++ thì mình dùng hàm string::replace
Em xem thử ví dụ này nhé, chỗ nào không hiểu em đặt câu hỏi. Về videos anh sẽ làm hehe, mà phải chờ cho khi nào “nông nổi” đã :trollface:
// replacing in a string
#include <iostream>
#include <string>
int main ()
{
std::string base="this is a test string.";
std::string str2="n example";
std::string str3="sample phrase";
std::string str4="useful.";
// replace signatures used in the same order as described above:
// Using positions: 0123456789*123456789*12345
std::string str=base; // "this is a test string."
str.replace(9,5,str2); // "this is an example string." (1)
str.replace(19,6,str3,7,6); // "this is an example phrase." (2)
str.replace(8,10,"just a"); // "this is just a phrase." (3)
str.replace(8,6,"a shorty",7); // "this is a short phrase." (4)
str.replace(22,1,3,'!'); // "this is a short phrase!!!" (5)
// Using iterators: 0123456789*123456789*
str.replace(str.begin(),str.end()-3,str3); // "sample phrase!!!" (1)
str.replace(str.begin(),str.begin()+6,"replace"); // "replace phrase!!!" (3)
str.replace(str.begin()+8,str.begin()+14,"is coolness",7); // "replace is cool!!!" (4)
str.replace(str.begin()+12,str.end()-4,4,'o'); // "replace is cooool!!!" (5)
str.replace(str.begin()+11,str.end(),str4.begin(),str4.end());// "replace is useful." (6)
std::cout << str << '\n';
return 0;
}
1 Like
mong a nông nổi nhiều nhiều nữa . chứ video của a vẫn thiếu nhiều phần mà. nông nỗi nữa đi a.
2 Likes