sách gpt4 ăn đã đi

c++ - 如何打开一个txt文件而不删除之前的内容

In lại 作者:搜寻专家 更新时间:2023-10-31 01:06:14 26 4
mua khóa gpt4 giày nike

所以我希望能够在控制台关闭后打开文件并能够继续添加到文件中。

int chính(){
string inputWord;
ofstream theFile("Info.txt");
cout << "Type Word or Sentence: ";

while(getline(cin,inputWord)){
cout << "Type Word or Sentence: ";
theFile << "Word or Sentence: " << inputWord;
theFile << "(Regular Value): " << ch2n(inputWord) << endl;
theFile << "(Other Value): " << char2num(inputWord) << endl;
theFile << "(Sum): " << ch2n(inputWord) + char2num(inputWord) << endl;
theFile << "(Difference): " << ch2n(inputWord) - char2num(inputWord) << endl;
theFile << "(Total): " << ch2n(inputWord) + (ch2n(inputWord)+char2num(inputWord)) + (ch2n(inputWord)-char2num(inputWord)) + char2num(inputWord) << endl << endl;

if(inputWord == "")return 0;
}
}

câu trả lời hay nhất

您必须以追加模式打开文件流:

std::ofstream out("Info.txt", std::ios_base::app);
// ^^^^^^^^^^^^^^^^^^

关于c++ - 如何打开一个txt文件而不删除之前的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21176987/

26 4 0
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress