Problems with names with 2 or more parts.

I want to get the name of the street of a user who may have 1, 2 or 3 part names but I get only the first part in my output.

1
2
3
4
5
6
7
8
9
10
11
12
13
#include  <iostream>

using namespace std;

int main ()
{ char street[30];

 cout<< "street:\n";


 cin>> street; //possible input "abc street" or "old abc street"

cout<< street  << "\n"; }


desired result-abc street or old abc street.

Actual result- abc or old. :-(
cin.getline(street, sizeof(street));

http://www.cplusplus.com/reference/istream/istream/getline/

note: there are two versions of getline(). If you use std::string, the syntax is slightly different:
http://www.cplusplus.com/reference/string/string/getline/
Last edited on
Ah.. I thought it would work with cin and cout alone.. :-D Thank you 4 helping. I'll go through that section now.
Last edited on
Topic archived. No new replies allowed.