我有一个看起来像的文件:
4
Sam Stone
2000
Freida Flass
100500
Tammy Flass
5000
Rich Raptor
55000
我正在尝试从中读取,但 while 循环中的第一个 getline 始终不返回任何内容。int 4 被正确读取。
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <vector>
#include <string>
using namespace std;
const int SIZE = 60;
struct person
{
string name;
double money;
};
int main()
{
char filename[SIZE];
string input;
char inputs [50];
int value;
int count = 0;
vector<person> Members;
ifstream inFile;
inFile.open("carinfo.txt");
if (!inFile.is_open()){ cout << "Could not open fle"; }
inFile >> value;
Members.resize(value);
while (inFile.good())
{
inFile.getline(inputs, SIZE); //getline(inFile, input, '\n');
inFile >> value;
count++;
}
cout << "Total lines = " << count;
system("pause");
return 0;
}