0
我在嘗試替換文件中的文本時遇到問題。C++爲什麼不將此代碼寫入文件
#include <iostream>
#include <fstream>
void Place(string& seek)
{
fstream myfile;
string holder = "";
myfile.open("testfile.txt");
while (seek != holder)
{
myfile >> holder;
}
myfile << "300";
myfile.close();
}
使用此我能夠讀取我正在嘗試更改的行,但它不適用於寫入。
string Pull(string& seek)
{
fstream myfile;
string holder = "";
myfile.open("test.txt");
while (seek != holder)
{
myfile >> holder;
}
myfile >> holder;
myfile.close();
return holder;
}
([使用fstream的和刪除文件的其餘部分覆蓋在一個文件中的一些文本]的可能的複製https://stackoverflow.com/questions/ 13112026 /覆蓋文件中的某些文本使用fstream和刪除文件的其餘部分) – Ari0nhh
'myfile >>持有者;'將空字符串寫入文件。 –
沒有將選擇從文件夾入持有者。它用於在文件中移動,在第二個示例中從中提取信息。目前,如果我試圖在while循環之後再次發生任何事情,它並不會令人畏懼。某種程度上while循環會產生干擾嗎? – Lugh