【发布时间】:2019-12-30 08:37:07
【问题描述】:
我是 C++ 新手,并试图在这一行添加一个变量:ifstream studentPaper(paper); 生病将纸张传递给此功能并想在那里使用它。字符串纸有我的文件位置(/name/file.txt)
如果我把我的文件名放在那里,我不会收到任何错误 = ifstream studentPaper("/name/file.txt"); 但是当我将文件位置保存到一个字符串中并给它一个字符串时,我会得到错误 = ifstream studentPaper(paper);
我怎样才能做到这一点而不会出错
void matchGrades(string paper) {
string aa= "asd";
ifstream studentPaper(paper);
ifstream base("base.txt");
int grade=3;
while ((!studentPaper.eof()) && (!base.eof())) {
string l1,l2;
getline(studentPaper,l1);
getline(base,l2);
if(l1==l2){
grade += 3;
} else {
grade -= 3;
}
}
studentPaper.close();
base.close();
cout << grade;
【问题讨论】: