为什么这些文件没有打开? 自从第一天以来,我在C++中打开文件遇到了问题,我遇到的问题是让特定的文件再次打开。我做错什么了吗?我试过这个部分,后面有没有.txt,也试过把它放在C驱动器中,只是试着这样做,但还是不起作用

为什么这些文件没有打开? 自从第一天以来,我在C++中打开文件遇到了问题,我遇到的问题是让特定的文件再次打开。我做错什么了吗?我试过这个部分,后面有没有.txt,也试过把它放在C驱动器中,只是试着这样做,但还是不起作用,c++,io,fstream,C++,Io,Fstream,代码: 错误部分一直显示,因此我假设这意味着文件尚未打开,或者文件内容将被复制到数组中。文件名字符串中需要双反斜杠 correctAnswers.open("C:\\CorrectAnswers"); studentAnswers.open("C:\\StudentAnswers"); 您需要在文件名字符串中使用双反斜杠 correctAnswers.open("C:\\CorrectAnswers"); studentAnswers.open("C:\\StudentAnswers");

代码:


错误部分一直显示,因此我假设这意味着文件尚未打开,或者文件内容将被复制到数组中。

文件名字符串中需要双反斜杠

correctAnswers.open("C:\\CorrectAnswers");
studentAnswers.open("C:\\StudentAnswers");

您需要在文件名字符串中使用双反斜杠

correctAnswers.open("C:\\CorrectAnswers");
studentAnswers.open("C:\\StudentAnswers");
< C++字符串中的a \“”引入了一个转义序列。要得到一个实际的“\”,您需要逃逸-即C:\\CorrectAnswers

一个正确的错误/警告配置的编译器通常会说一个未知的转义序列[C.< /P> < P> a \,在一个C++字符串中引入一个转义序列。要得到一个实际的“\”,您需要逃逸-即C:\\CorrectAnswers


一个具有正确错误/警告配置的好编译器通常会说未知转义序列\C.

哦,天哪。谢谢你们。我这里有一个完整的程序,因为那个特定的部分而无法工作。我还必须在末尾添加.txt以使其指向正确的方向

ifstream correctAnswers;
ifstream studentAnswers;

correctAnswers.open("C:\\CorrectAnswers.txt");
studentAnswers.open("C:\\StudentAnswers.txt");

if (correctAnswers && studentAnswers) {
    for (int i = 0; i < SIZE; i++) {
        correctAnswers >> answerKey[i];
        studentAnswers >> studentKey[i];

    }
}
else {
    cout << "error" << endl;
}

哦,我的上帝。谢谢你们。我这里有一个完整的程序,因为那个特定的部分而无法工作。我还必须在末尾添加.txt以使其指向正确的方向

ifstream correctAnswers;
ifstream studentAnswers;

correctAnswers.open("C:\\CorrectAnswers.txt");
studentAnswers.open("C:\\StudentAnswers.txt");

if (correctAnswers && studentAnswers) {
    for (int i = 0; i < SIZE; i++) {
        correctAnswers >> answerKey[i];
        studentAnswers >> studentKey[i];

    }
}
else {
    cout << "error" << endl;
}