2017-08-28 258 views
-4

建立在Linux的一个空文件我想创建一个使用C的Ubuntu ++一个空文件,我尝试过很多办法,并不断失败,并显示此错误如何用C++

error: no matching function to 'std::basic_ofstream::open(std::cxxll::...

我的代码:

ifstream f(saltFile.c_str()); 

if (f.good()) 
{ 
    cout << saltFile + " file already existed" << endl; 
} 
else 
{ 
    ofstream file; 
    file.open (saltFile, ios::out); 
    cout << saltFile << " created!" << endl; 
} 
+3

(https://stackoverflow.com/questions/478075/creating-files-in-c) – Mureinik

+0

'file.open(saltFile.c_str [在C++中创建的文件]的可能的复制( ),...'。 C++ 98版本只有一个'const char *'的原型:http://www.cplusplus.com/reference/fstream/ofstream/open/ – mch

+1

您使用的是哪种编译器?你是否启用C++ 11或更高版本? – NathanOliver

回答

0

如果你有一个C++ 11或更高版本的编译器,你可以使用:

file.open (saltFile, ios::out); 

如果你有一个预先C++编译器11,您甲肾上腺素ED使用:

file.open (saltFile.c_str(), ios::out);