ios::nocreate error while compiling a C++ code

五迷三道 提交于 2019-12-01 19:58:36

ios::nocreate is not part of standard C++ - what are you expecting it to do?

Edit: From a Google, it seems like it was intended to prevent the file being created if it doesn't already exist. This is the default for ifstreams anyway, so you can just say:

ifstream f( filename );
if ( ! f.is_open() ) {
    // open failed - probably because infput file does not exist  
}

Opening a file in read mode (ios::in) won't create it if it doesn't exist. You can just leave off the non-standard nocreate. And since in is the default for ifstream:

ifstream tempStr (argv[4]);

You can open the file as a filehandle using fopen and O_CREAT|O_EXCL and then convert it to a stream using

__gnu_cxx::stdio_filebuf<char> filebuf(posix_handle, std::ios::out);
    ostream os(&filebuf);

this uses a non standard extension defined in . If anyone has a better solution, i really want to know!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!