【发布时间】:2015-05-01 12:27:42
【问题描述】:
我正在读取一个带有制表符分隔的名字、姓氏和邮政编码的输入文件。其中有 25 个。我正在尝试将其读入,将其存储到对象中并再次打印出来。
代码如下:
// 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的声明。 -
对不起,这里是: // 数组声明 Person* 个人[25];