簡體   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