发生这种情况有什么原因吗?我以两个不同的名称保存了相同的文件。一个是test.csv,另一个是text.txt。内容相同。当我使用 ifstream 对象打开 text.txt 时,我的代码按预期运行并将数据解析为一个对象。当我打开 test.csv 时,我的 ifstream 对象没有收集任何数据,并且代码出现故障。打开 .csv 而不是 .txt 时,是否需要采取任何额外的步骤?
这是实际执行输入的代码:
Team::Team(ifstream& fin)
{
string temp;
stringstream convert;
//Get team #
getline(fin, temp, ',');
idNumber = stringToInt(temp);
//Get team letter
getline(fin, temp, ',');
idLetter = temp[0];
//Get team name
getline(fin, name, ',');
//Get team type
getline(fin, type, ',');
//Get team rating
getline(fin, temp, ',');
rating = stringToDouble(temp);
//Get team notes
getline(fin, notes, ',');
//Get toss info
getline(fin, temp, ',');
canToss = stringToBool(temp);
getline(fin, tossType, ',');
//Get female info
getline(fin, temp, ',');
hasFemales = stringToBool(temp);
getline(fin, temp, ',');
femaleNumber = stringToInt(temp);
getline(fin, temp, ',');
femaleRating = stringToDouble(temp);
//Get Auto info
getline(fin, temp, ',');
hasAuto = stringToBool(temp);
getline(fin, autoType, ',');
getline(fin, temp, ',');
autoScore = stringToInt(temp);
//Get Drive Info
getline(fin, temp, ',');
driveMotors = stringToInt(temp);
getline(fin, temp, ',');
driveRatio = stringToDouble(temp);
getline(fin, driveType, ',');
//Get hang info
getline(fin, temp, ',');
canHang = stringToBool(temp);
getline(fin, hangType, ',');
//Get stash info
getline(fin, temp, ',');
canStash = stringToBool(temp);
//Get lift indo
getline(fin, temp, ',');
liftMotors = stringToInt(temp);
getline(fin, temp, ',');
liftRatio = stringToDouble(temp);
getline(fin, liftType, ',');
//Get competition info
getline(fin, temp, ',');
driverSkills = stringToInt(temp);
getline(fin, temp, ',');
programmingSkills = stringToInt(temp);
getline(fin, temp, ',');
ranking = stringToInt(temp);
getline(fin, temp, ',');
wins = stringToInt(temp);
getline(fin, temp, ',');
ties = stringToInt(temp);
getline(fin, temp, ',');
losses = stringToInt(temp);
getline(fin, temp);
SPs = stringToInt(temp);
}