Problems with textfile

Hi!

I have problems writing data to a text file. The program jumps over the name of the second, third....person, and I can't really figure out why. I have tried cin.ignore, but it doesn't work as I wish. Somebody that has an idea?

This is my code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

        do 
	{
		memset(name,0,SIZE);
		memset(pNr,0,SIZE);

		cout << "\n\nYour name, please ";
		cin.getline(name, SIZE);
		
		cout << "\nEnter your phone number: ";
		cin.getline(pNr, SIZE);

		out << name << ", " << pNr << "\n";
		
		cout << "\nDo you want to continue to enter data? ";
		cin >> answer;
	
	} while (answer == 'Y' || answer == 'y');

I do not see where you are writing data to a text file. But it is obvious that in your snip of code nothing will be read into pNr, The problem is that cin.getline( name, SIZE ) reads either SIZE-1 bytes or until new line character will not be encountered. And it does not read new line character. So next read operation sees that the next character is new line character and reads nothing. You should skip new line character after cin.getline( name, SIZE ).
Topic archived. No new replies allowed.