UniqueFile.cc:64:初始化`void 的参数2 std :: basic_fstream< _CharT, _Traits> :: open(const char *,std :: _ Ios_Openmode )[with _CharT = char, _Traits = std :: char_traits< char>]'' make:*** [UniqueFile.o]错误1 " Mike - EMAIL IGNORED" < M _ ************* @ yahoo.com>写道: Victor Bazarov写道: Mike - EMAIL IGNORED < M _ ************* @ yahoo.com>写了... 使用RH9,来自这个片段: fstream theStream_; string fPath =" myFile" ;; int mode = O_EXCL | O_CREAT; theStream_.open(fPath.c_str(),mode); 'O_EXCL是什么| O_CREAT''表达式在''fstream :: open''吗?你应该使用''std :: ios_base''中的常量...... 根据什么标准?什么页面/子句/段落?我的标准副本声明第二个参数的类型为''std :: ios_base :: openmode''。 提前感谢您的支持麦克。 -I ../ MdbUtil -c -o UniqueFile.o UniqueFile.cc UniqueFile.cc:在成员函数中`void MdbUtil :: UniqueFile :: open(const char *, const char *,int,int,const char *)'': UniqueFile.cc:64:从`int'转换无效'to `std :: _ Ios_Openmode''UnityFile.cc:64:初始化`void 的参数2 std :: basic_fstream< _CharT, _Traits> :: open(const char *,std :: _ Ios_Openmode)[with _CharT = char,_Traits = std :: char_traits< char>]'' make:*** [UniqueFile.o]错误1 是的,我看到了我的现在错了。我的要求是打开一个ofstream,如果文件已经存在则让它失败。我查看了std :: ios_base中的常量,并且像旧的fstream功能一样,它似乎没有语义来执行此操作。如果我对此是正确的,检查文件存在的最佳方法是什么? (a)请不要't top-post (b)我在C ++中知道检查文件是否存在的唯一方法是打开 文件进行阅读[只有]并检查它是否成功。我的 猜测如果它没有成功(没有这样的文件),那么 你重新打开流写进行并继续使用它(如果我 正确理解你的意图。 Victor Using RH9, from this fragment:fstream theStream_;string fPath = "myFile";int mode = O_EXCL | O_CREAT;theStream_.open(fPath.c_str(),mode);I get the failure shown below. According to the man pages andthe standard, the second argument should be an int.Thanks in advance for your help.Mike.--g++ -I. -I../MdbUtil -c -o UniqueFile.o UniqueFile.ccUniqueFile.cc: In member function `void MdbUtil::UniqueFile::open(const char*,const char*, int, int, const char*)'':UniqueFile.cc:64: invalid conversion from `int'' to `std::_Ios_Openmode''UniqueFile.cc:64: initializing argument 2 of `void std::basic_fstream<_CharT,_Traits>::open(const char*, std::_Ios_Openmode) [with _CharT = char, _Traits= std::char_traits<char>]''make: *** [UniqueFile.o] Error 1 解决方案 "Mike - EMAIL IGNORED" <m_*************@yahoo.com> wrote... Using RH9, from this fragment: fstream theStream_; string fPath = "myFile"; int mode = O_EXCL | O_CREAT; theStream_.open(fPath.c_str(),mode);What does ''O_EXCL | O_CREAT'' expression doing in ''fstream::open''?You are supposed to use constants from ''std::ios_base''... I get the failure shown below. According to the man pages and the standard, the second argument should be an int.According to what standard? What page/clause/paragraph? My copy of thestandard states that the second argument has the type''std::ios_base::openmode''. Thanks in advance for your help. Mike. -- g++ -I. -I../MdbUtil -c -o UniqueFile.o UniqueFile.cc UniqueFile.cc: In member function `void MdbUtil::UniqueFile::open(constchar*, const char*, int, int, const char*)'': UniqueFile.cc:64: invalid conversion from `int'' to `std::_Ios_Openmode'' UniqueFile.cc:64: initializing argument 2 of `voidstd::basic_fstream<_CharT, _Traits>::open(const char*, std::_Ios_Openmode) [with _CharT = char,_Traits = std::char_traits<char>]'' make: *** [UniqueFile.o] Error 1Yes, I see my error now. My requirement is to open an ofstream,and have it fail if the file already exists. I looked at theconstants in std::ios_base, and like the old fstream capability,it does not appear to have the semantics to do this. If I amcorrect about this, what is the best way to check for theexistence of a file?Thanks again for your help,Mike.Victor Bazarov wrote: "Mike - EMAIL IGNORED" <m_*************@yahoo.com> wrote... Using RH9, from this fragment: fstream theStream_; string fPath = "myFile"; int mode = O_EXCL | O_CREAT; theStream_.open(fPath.c_str(),mode); What does ''O_EXCL | O_CREAT'' expression doing in ''fstream::open''? You are supposed to use constants from ''std::ios_base''... I get the failure shown below. According to the man pages and the standard, the second argument should be an int. According to what standard? What page/clause/paragraph? My copy of the standard states that the second argument has the type ''std::ios_base::openmode''. Thanks in advance for your help. Mike. -- g++ -I. -I../MdbUtil -c -o UniqueFile.o UniqueFile.cc UniqueFile.cc: In member function `void MdbUtil::UniqueFile::open(const char*, const char*, int, int, const char*)'': UniqueFile.cc:64: invalid conversion from `int'' to `std::_Ios_Openmode'' UniqueFile.cc:64: initializing argument 2 of `void std::basic_fstream<_CharT, _Traits>::open(const char*, std::_Ios_Openmode) [with _CharT = char, _Traits = std::char_traits<char>]'' make: *** [UniqueFile.o] Error 1"Mike - EMAIL IGNORED" <m_*************@yahoo.com> wrote... Victor Bazarov wrote: "Mike - EMAIL IGNORED" <m_*************@yahoo.com> wrote... Using RH9, from this fragment: fstream theStream_; string fPath = "myFile"; int mode = O_EXCL | O_CREAT; theStream_.open(fPath.c_str(),mode); What does ''O_EXCL | O_CREAT'' expression doing in ''fstream::open''? You are supposed to use constants from ''std::ios_base''... I get the failure shown below. According to the man pages and the standard, the second argument should be an int. According to what standard? What page/clause/paragraph? My copy of the standard states that the second argument has the type ''std::ios_base::openmode''. Thanks in advance for your help. Mike. -- g++ -I. -I../MdbUtil -c -o UniqueFile.o UniqueFile.cc UniqueFile.cc: In member function `voidMdbUtil::UniqueFile::open(const char*, const char*, int, int, const char*)'': UniqueFile.cc:64: invalid conversion from `int'' to`std::_Ios_Openmode'' UniqueFile.cc:64: initializing argument 2 of `void std::basic_fstream<_CharT, _Traits>::open(const char*, std::_Ios_Openmode) [with _CharT =char, _Traits = std::char_traits<char>]'' make: *** [UniqueFile.o] Error 1 Yes, I see my error now. My requirement is to open an ofstream, and have it fail if the file already exists. I looked at the constants in std::ios_base, and like the old fstream capability, it does not appear to have the semantics to do this. If I am correct about this, what is the best way to check for the existence of a file?(a) Please don''t top-post(b) The only way I know in C++ to check if a file exists is to openthe file for reading [only] and check whether it succeeds. Myguess is that if it doesn''t succeed (there is no such file), thenyou re-open the stream for writing and continue using it (if Iunderstood your intentions correctly).Victor 这篇关于打开fstream的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!