linux 怎么支持c++11

linux 怎么支持c++11,第1张

linux是以C语言库为标准的系统,当然可以支持C++,支持C++11标准是编译器的事,现在gcc和clang都支持c++11了,连14都支持(貌似17快出来了),编译时加参数-std=C++11就可以比如:g++ hello.cpp -o hello.exe -std=c++11

在fstream类中,成员函数open()实现打开文件 *** 作,从而将数据流和文件进行关联,通过ofstream,ifstream,fstream对象进行对文件的读写 *** 作

函数:open()

<span style="font-family:Times New Romanfont-size:16px">

public member function

void open ( const char * filename,

            ios_base::openmode mode = ios_base::in | ios_base::out )

void open(const wchar_t *_Filename,

&nbsp&nbsp &nbsp&nbsp&nbsp &nbspios_base::openmode mode= ios_base::in | ios_base::out,

&nbsp&nbsp &nbsp&nbsp&nbsp &nbspint prot = ios_base::_Openprot);

</span>

参数: filename   *** 作文件名

mode        打开文件的方式

prot         打开文件的属性  

很多程序中,可能会碰到ofstream out("Hello.txt"), ifstream in("..."),fstream foi("...")这样的的使用,并没有显式的去调用open()函数就进行文件的 *** 作,直接调用了其默认的打开方式,因为在stream类的构造函数中调用了open()函数,并拥有同样的构造函数,所以在这里可以直接使用流对象进行文件的 *** 作,默认方式如下:

<span style="font-family:Times New Romanfont-size:16px">

ofstream out("...", ios::out)

ifstream in("...", ios::in)

fstream foi("...", ios::in|ios::out)

</span>

当使用默认方式进行对文件的 *** 作时,可以使用成员函数is_open()对文件是否打开进行验证


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/7409060.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-05
下一篇 2023-04-05

发表评论

登录后才能评论

评论列表(0条)

保存