string

For the following types of input

ira ira

( two words separated by a space)
i want to store two words separated by space in two different strings, so i used the following code

1
2
3
4
5
string a,b;
getline(cin, a,' ');
getline(cin, b);
cout << a.length();
cout << b.length();

but when i calculate the length of the string for the given case ( that is- "ira ira" ) it gives the answer as 4 and 3 respectively
Why doesn't it give answer as 3 and 3??
Last edited on
stick a breakpoint on line 4 and examine a and b.
Topic archived. No new replies allowed.