String ignore space

Hello there, Sorry if this has been asked before, but I cannot find an answer for this anywhere. I am taking my first C++ class and this problem came up which my professor referred as "Very easy" but I can't seem to figure it out. Also, sorry, I don't have the code with me but I do have pictures on the code I'm working on below.

http://i42.tinypic.com/2wd0xn5.jpg
http://i39.tinypic.com/11vqj5h.jpg
http://i39.tinypic.com/2wbtaon.jpg

My problem lies in the range of the lines 48-52, I am trying to run the program having the string line ignore the spaces, however when I run the program and I ask the user to input a phrase, for example "Hello World", the program will only display "World" This means that the code is discarding everything until the space. I want it to display the whole thing and if I don't apply the cin.ignore(1000, " ") it will freak out.

I'll try to highlight the essential part of code where the problem is.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
 #Include <iostream>
 #Include <string>
 using namespace std;

int_main()

string s;

cout << "Enter a sentence: ";
getline(cin, s);
cin.ignore(1000, " ");
cin >> s;
cout << s << endl;


Can Someone help me please?
closed account (o3hC5Di1)
Hi,

Why are you doing both getline(cin,s) and cin >>s?

Getline should get the whole sentence into s for you, i believe?

All the best,
NwN
Topic archived. No new replies allowed.