我尝试将字符串值从文本文件打印到控制台,但文件不打开。
#include "stdafx.h"
#include <iostream>
#include <string>
#include<fstream>
int main()
{
ifstream nameFile;
nameFile.open("E:\\Names.txt");
string a;
int studentCount = 0;
if (nameFile.is_open())
{
while (getline(nameFile, a)) {
cout << a << '\n';
studentCount++;
}
cout << studentCount;
}
else
cerr << "Unable to load file" << endl;}