Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/163.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 在C+中打开并写入现有的fstream而不覆盖/清除+;_C++_Visual Studio_Iostream_Fstream_Ofstream - Fatal编程技术网

C++ 在C+中打开并写入现有的fstream而不覆盖/清除+;

C++ 在C+中打开并写入现有的fstream而不覆盖/清除+;,c++,visual-studio,iostream,fstream,ofstream,C++,Visual Studio,Iostream,Fstream,Ofstream,我有一个现有的txt文件,我想能够写东西到它(在下一行),而不修改现有的内容。做这件事的好方法是什么 #include <iostream> ofstream myfile ("ex.txt"); #包括 流myfile(“ex.txt”); 似乎清除了所有现有文本。流myfile(“ex.txt”,ios_base::app)将以追加模式打开文件。每个写入操作都将附加到现有内容。使用ios\u base::app标志打开文件我建议您阅读有关该函数或。

我有一个现有的txt文件,我想能够写东西到它(在下一行),而不修改现有的内容。做这件事的好方法是什么

#include <iostream>
ofstream myfile ("ex.txt"); 
#包括
流myfile(“ex.txt”);

似乎清除了所有现有文本。

流myfile(“ex.txt”,ios_base::app)将以追加模式打开文件。每个写入操作都将附加到现有内容。

使用
ios\u base::app
标志打开文件

我建议您阅读有关该函数或。