ofstream基本用法

來源:

https://zh.cppreference.com/w/cpp/io/basic_ofstream/basic_ofstream

 

#include <fstream>
#include <utility>
#include <string>
int main()
{
    std::ofstream f0;
    std::ofstream f1("test.bin", std::ios::binary);
    std::string name = "example.txt";
    std::ofstream f2(name);
    std::ofstream f3(std::move(f1));
}

std::ofstream f1(file_path, mode)打開一個輸出到test.bin的文件,後面的要求:

std::ios_base::openmode

常量	解釋
app	每次寫入前尋位到流結尾
binary	以二進制模式打開
in	爲讀打開
out	爲寫打開
trunc	在打開時捨棄流的內容
ate	打開後立即尋位到流結尾

string.c_str() 作用與string.data()相同

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章