Whats happening in this code?

Hi guys,

I got this code, but dont understand why its not working.
It has something to do with cin and getline, but i dont see it..
Could you help me?

This is the code:

int number;
string street_nr, location_name;
cout << "Give number: " ;
cin >> number;
cout << "Street name+housenr :" ;
getline (cin, street_nr) ;
cout << "location: ";
getline (cin, location_name);

This is the result:

Give number: 1234
Street name+housenr : Location : _


What happens? :(
This should work;

int number;
string street_nr, location_name;
cout << "Give number: " ;
cin>>number;
cin.get();
cout << "Street name+housenr :" ;
getline (cin, street_nr) ;
cout << "location: ";
getline (cin, location_name);

problem was that when you enter the integer "number" and press "enter", the program reads the newline as an input to the cin.getline() and that's the reason it looks like it has skipped it. Hope that helps!
Thanks for response.
Im going to try it :D
MrMajestyk that was nice
What was nice?

This code doesnt give me any result at all :(.
It just "process returned" after inputting number, street name+housenr and location..
1
2
3
4
5
6
7
8
9
int number;
string street_nr, location_name;
cout << "Give number: " ;
cin >> number;
cout << "Street name+housenr :" ;
getline (cin, street_nr) ;

getline (cin, location_name);
cout << "location: "<<street_nr<<"location"<<location
Its semi-working now :D
Thanks
Topic archived. No new replies allowed.