繁体   English   中英

无法在C ++中使用附加模式在文件中插入数据

[英]Not able to insert data in file using append mode in c++

我的代码是这样的:

#include<iostream>
#include<fstream>
using namespace std;

int main()
{
fstream file;
file.open("abc.txt",ios::app);
file<<"hello";
file.close();
return 0;
}

上面的代码正在创建一个空文件。

请任何人指出我要去哪里了。

打开文件时,除了指定append( ios::app )外,还必须指定要输出到文件( ios::out )。 您将它们与按位或( | )组合,因为它们表示单个位标志。

#include<iostream>
#include<fstream>
using namespace std;

int main()
{
    fstream file;
    file.open("abc.txt",ios::app | ios::out);
    file << "hello";
    file.close();
    return 0;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM