Jump from string

Hello,
Where is the problem?
I can't get str and jump from it. I need solution for beginners
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;
struct  test
{
	int id;
	string str;
	string str2;
} arr[50];
int _tmain(int argc, _TCHAR* argv[])
{
	int n ;
	cout<<"n";
	cin>>n;
	for (int i = 0; i < n; i++)
	{
		cout<<"str";
		getline(cin,arr[i].str); //jump from it
		cout<<"next str";
		getline(cin,arr[i].str2);
		cout<<"id";
		cin>>arr[i].id;
	}


	return 0;
}
Last edited on
> I can't get str and jump from it.
No idea what you are trying to say.


Notice that cin>>n does not extract whitespace. If you pressed "42\n" then "\n" would remain in the buffer.
getline() stops at the line break, so it will see a blank line. To fix that you may use cin.ignore();
Last edited on
Topic archived. No new replies allowed.