一个ifstream 打开文件的异常
一个ifstream 打开文件的错误C/C++ codevoid bayes(){ifstream infile(ls-train.txt)ifstream inputif
一个ifstream 打开文件的错误
C/C++ codevoid bayes(){ ifstream infile("ls-train.txt"); ifstream input; if(!infile) { cout << "dict open error "<<endl; } string word; string filename; char *temp = (char *)malloc(sizeof(char) * 10) ; int i = 1; int type; /*这一步 是统计每一分类 ,他每个单词出现的次数*/ while(infile >> filename) { //strcpy(temp,filename.c_str()) ; //type = temp[0] - '0'; [color=#FF0000] input( filename.c_str() ); //这一步报错 : no match for call to ‘(std::ifstream) (const char*)[/color] if( ! input) ; cout << filename << " open error" << endl; input.close(); } infile.close();
请大牛指教
[解决办法]没有你那样的函数调用...
input( filename.c_str() ); // input是一个对象,你这样写,不知是什么含义?
[解决办法][解决办法]初始化只能在对象定义时,其他时候是赋值,不是初始化。
[解决办法]楼主,你这样定义一个变量ifstream input
然后又这样input( filename.c_str() ),在这里input是一个变量名而已,你这样写肯定不符合语法.
如果你要赋值的话,可以构造一个ifstream对象再给input,像这样input=ifstream(filename.c_str()),或者
像楼主写的那样ifstream input( filename.c_str() );
希望对你有帮助!