C++读取txt文件失败的可能性
编程环境: VSCode
先给出正确格式:
ifstream infile;
infile.open(“F:\\studyroom\\students.txt”);
以下为可能的错误
错误1:没有使用\\
只有1个\
ifstream infile;
infile.open(“F:\studyroom\students.txt”);
写成了/
ifstream infile;
infile.open(“F:/studyroom/students.txt”);
错误2:文件名为中文
ifstream infile;
infile.open(“F:\\studyroom\\算法\\students.txt”);
发现这个还是很偶然的,我把鼠标放在了中文那块,提示里出现的是乱码,引起了我的怀疑。把txt文件移到了一个只有英文文件夹名的目录下,就解决了。