how to prevent getline from skipping a line

ive read that its best if you dont put getline with >> but i didnt have a choice.

1
2
3
4
5
6
7
8
9
10
  for (int x = 0; x < 500; x++)
			{
				getline(file, index[x]);
				getline(file, title[x]);
				getline(file, author[x]);
				getline(file, description[x]);
				getline(file, ISBN[x]);
				file >> copys[x];
				file >> check[x];
			}	


what this does:
- gets the input file "file" and assign the data into index, title, author, etc.
- the last 2 are ints

what it prints out:
- assuming that the file has 500 different titles and indexes, etc.
- it prints out the everything and copys[x] + 1, check[x]-1
- after the first grab on the file data it skipped a line.
- so index becomes blank, title becomes the index number, and everything just moves down

http://stackoverflow.com/a/21567292
In short:
1
2
3
for (int x = 0; x < 500; x++)	{
    std::getline(file >> std::ws, index[x]);
//... 
uhh.. sorry. never really understood what the std:: meant.

can u repost that without the std?

i tried puting getline(file >> ws, index[x]) and nothing happened

EDIT:
NVM. i forgot i changed the global var int to a char when i was testing something. after i put the getline(file >> ws, index[x]) in, it worked. GOD BLESS YOU BUDDY :)
Last edited on
Topic archived. No new replies allowed.