问题描述
int main()
{
cout << "Please enter the name of the file: ";
string fileName;
getline(cin,fileName);
ifstream file("C:\\Users\\Faisal\\Desktop\\Programs\\"+fileName.c_str(),ios::in);
string line;
for (int count = 1; !file.eof(); ++count)
{
getline(file,line);
cout << line << endl;
if (count % 24 == 0) system("Pause");
}
system("Pause");
}
以下是我的错误
[错误]类型为'const char [34]'和'const char *'的无效操作数到二进制'operator +'
更新1
按照@drescherjm注释。我已经更新了代码
int main()
{
cout << "Please enter the name of the file: ";
string fileName;
string pathName = "C:\\Users\\Faisal\\Desktop\\Programs\\";
getline(cin,fileName);
string filetoOpen = pathName + fileName;
ifstream file(filetoOpen.c_str());
if (!file){
// There was an error so display an error
// message and end the PROGRAM.
cout << "Error opening " << fileName << endl;
exit(EXIT_FAILURE);
}
string line;
for (int count = 1; !file.eof(); ++count)
{
getline(file,line);
cout << line << endl;
if (count % 24 == 0) system("Pause");
}
system("Pause");
}
Please enter the name of the file: ali
Error opening ali
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)