<分区>
我正在学习 C++,当我尝试在 ifstream 方法中使用 String 时遇到了一些麻烦,如下所示:
string filename;
cout << "Enter the name of the file: ";
cin >> filename;
ifstream file ( filename );
完整代码如下:
// obtaining file size
#include <iostream>
#include <fstream>
using namespace std;
int main ( int argc, char** argv )
{
string file;
long begin,end;
cout << "Enter the name of the file: ";
cin >> file;
ifstream myfile ( file );
begin = myfile.tellg();
myfile.seekg (0, ios::end);
end = myfile.tellg();
myfile.close();
cout << "File size is: " << (end-begin) << " Bytes.\n";
return 0;
}
这里是Eclipse的报错,方法前的x:
no matching function for call to `std::basic_ifstream<char, std::char_traits<char> >::basic_ifstream(std::string&)'
但是当我尝试在 Eclipse 中编译时,它在方法之前放置了一个 x,这表明语法中有错误,但是语法中有什么错误呢?谢谢!