我正在用制表符分隔的名字,姓氏和邮政编码阅读输入文件。其中有25个。我正在尝试读取它,将其存储到对象中并再次打印出来。C++读取文本文件,存储对象并打印输出数组
下面的代码:
// Reading in from an input file
ifstream inputFile("nameInput.txt");
string line;
for(int i = 0; i<25; i++){
while (getline(inputFile, line))
{
istringstream getInput(line);
string tempFName, tempLName;
int tempZip;
getInput >> tempFName >> tempLName >> tempZip;
// Creating new Person objects with the data
persons[i] = new Person(tempFName, tempLName, tempZip);
}
inputFile.close();
// Printing out String representation of the Person
persons[i]->toString();
}
虽然它编译,在运行时,这是错误我得到:87023
分段故障:11
请帮助!
向我们展示'persons'的声明。 – LogicStuff
对不起,这里是:\t //数组声明 \t人*人[25]; – swati