Extracting substrings

My situation is as follows:

#include <iostream>
#include <string>

cin >> word;
cout << word.length();
[suppose that the string "I am" was input by the user.]

Now, when I use the code word.length(), the output turns out to be 1 instead of 4. I am assuming that once the first space in "I am" is reached, the function stops counting ahead and as a result the length of the string is returned to be 1 instead of 4.

Is there a way to make the system return the full length of the input string?
You didnt declare word , but using getline(cin, word) should work
But how do I use getline(cin, word) to get the exact number of letters in the input string? I mean, what is the precise code needed?
Topic archived. No new replies allowed.