我刚刚在这个答案中发现了一条评论说iostream::eof在循环条件下使用"几乎肯定是错误的".我通常使用类似的东西while(cin>>n)- 我猜是隐式检查EOF,为什么检查eof显式使用while (!cin.eof())错误?
它与scanf("...",...)!=EOF在C中使用有何不同(我经常使用没有问题)?
在C++中是否可以用另一个字符串替换字符串的一部分?
基本上,我想这样做:
QString string("hello $name");
string.replace("$name", "Somename");
Run Code Online (Sandbox Code Playgroud)
但我想使用标准C++库.
我想替换文件中的一行文本,但我不知道它的功能.
我有这个:
ofstream outfile("text.txt");
ifstream infile("text.txt");
infile >> replace whit other text;
Run Code Online (Sandbox Code Playgroud)
对此有何答案?
我想念,在文件的某些行添加文字...
例
infile.add(text, line);
Run Code Online (Sandbox Code Playgroud)
C++是否具有此功能?
嗨,我想覆盖特定文件中的内容(对象)我已设置位置,但它总是添加到文件的末尾
码
int InputIO::editPatient(int location,Obj P){
int positon=location*sizeof(P);
f.open("File.dat",ios::in|ios::out|ios::app|ios::binary|ios::ate);
f.seekp(0,ios::beg);
f.seekp(positon,ios::cur);
f.write((char*)&P,sizeof(Movie));
f.close();
return 0;
}
Run Code Online (Sandbox Code Playgroud)