Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/137.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.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++;_C++_File_Export_Edit - Fatal编程技术网

C++ 如何编辑已在C++;

C++ 如何编辑已在C++;,c++,file,export,edit,C++,File,Export,Edit,我知道如何将数据导出到txt文件,但如果我已经创建了txt文件,那么如何编辑不适用于数据的txt文件已经存在。。 这也意味着在已经有数据的txt文件中添加一个新的数据行。您要查找的是将您写入的内容附加到文件末尾。您要查找的是将您写入的内容附加到文件末尾。您可以使用fstream(#include): //声明变量“file” std::fstream文件; //打开名为“data.txt”的文件进行写入(std::fstream::app允许您在文件末尾添加文本) 打开(“data.txt”,s

我知道如何将数据导出到txt文件,但如果我已经创建了txt文件,那么如何编辑不适用于数据的txt文件已经存在。。
这也意味着在已经有数据的txt文件中添加一个新的数据行。

您要查找的是将您写入的内容附加到文件末尾。

您要查找的是将您写入的内容附加到文件末尾。

您可以使用fstream(#include):

//声明变量“file”
std::fstream文件;
//打开名为“data.txt”的文件进行写入(std::fstream::app允许您在文件末尾添加文本)
打开(“data.txt”,std::fstream::in | std::fstream::out | std::fstream::app);
//无法打开文件
如果(!file.is_open()){
//执行某些操作,例如打印错误消息:std::cout您可以使用fstream(#include):

//声明变量“file”
std::fstream文件;
//打开名为“data.txt”的文件进行写入(std::fstream::app允许您在文件末尾添加文本)
打开(“data.txt”,std::fstream::in | std::fstream::out | std::fstream::app);
//无法打开文件
如果(!file.is_open()){

//做一些事情,例如,打印错误消息:std::cout您能给我们看一些代码,并更清楚地解释您实际想要“编辑”的内容吗?在追加模式下打开,追加文本,关闭它。您能给我们看一些代码,并更清楚地解释您实际想要“编辑”的内容吗?在追加模式下打开,追加文本,关闭它。
// declare variable "file"
std::fstream file;
// open file named "data.txt" for writing (std::fstream::app lets you add text to the end of the file)
file.open("data.txt", std::fstream::in | std::fstream::out | std::fstream::app);
// could not open file
if(!file.is_open()) {
    // do something, e.g. print error message: std::cout << "Couldn't open file." << endl;
// file is open, you can write to it
} else {
    file << "\n"; // add a new line to the file
    file.close(); // close file
}