Ifstream reads "" after first record

I have been assigned to create a program that is supposed to extract all the data from each row of a file into a struct. Each row in the file contains:
1) A baby name
2) The percent frequency with which that name is assigned to a baby
3) The number of babies with that name
4) A popularity rank

Each row looks something like this: ANNELISE 0.405 1,011,563 14
The trouble I'm having is that my program seems to be unable to get past the first baby name.
UPDATE: It appears that "babyName.number" is not being read correctly. It's the comma's fault!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
 using namespace std;
struct Record
{
	string name;
	float percentFrequency;
	long int number;
	int rank;
};
int main()
{
for (int i = 0; i < 99; i++)
				{
					Record babyName;
					inputStream >> babyName.name >> babyName.percentFrequency >> babyName.number >> babyName.rank;
					mbstowcs_s(&returnCode,wcstr,babyName.name.c_str(),MAX_LOADSTRING);
}
return 0;


Last edited on
What are you doing about those commas that are contained in your stream, remember that the extraction stops when it encounters an illegal character.

C++ doesn't read numbers like 1,011,563. You need to change that to 1011563.
You can read the babyName.number first with getline, remove the ',' and finally convert to an long int.
If you try getline() you're probably going to need to insure you skip leading whitespace and use a delimiter that is different from the default ('\n')

Topic archived. No new replies allowed.