我需要读取一个文件并将其转换为一个字符串数组,但是当它读取文件时它不会在数组中放入任何内容。这是我当前的代码:
string code[200];
string name;
int lines;
string filename;
int readfile(){
ifstream inFile;
int counter = 0;
cout << "Which file would you like to open?\n";
cin >> filename;
countlines();//counts total lines of file
inFile.open(filename);
if(inFile.fail())
{
cout << "File did not open correctly, please check it\n";
system("pause");
exit(0);
//return 1;
}
inFile >> name;
for (int i=0;i < lines; i++)
{
inFile >> code[i];
if (!inFile)
cout << "Error" << endl;
break;
}
inFile.close();
cout << "Now opened: " << name << endl;
return 0;
}