C++ .length() stops counting number of letters when spaces appear -


I have a loop for this program sometime. I want it so much that this program runs for many characters because the user In input it works when there is no free space in the user input, but when it appears in the spot, then as soon as the count of letters is stopped counting. Here's the full code:

  #include & lt; Iostream & gt; #include & lt; String & gt; #include & lt; Vector & gt; using namespace std; Of vector & lt; String & gt; Opposition = "B", "C", "D", "F", "G", "H", "J", "K", "L", "M", "N", "P" , "Q", "r", "s", "t", "v", "w", "x", "y"}; Of vector & lt; String & gt; Vowel = {"one", "e", "i", "o", "u"}; Int count_val = 0; String user_translate; Int main () {cout & lt; & Lt; "Enter the word you want:"; Cin & gt; & Gt; User_translate; While (count_val & lt; user_translate.length ()) {if (user_translate [count_val] == '') {cout & lt; & Lt; "No sentence!"; } Cout & lt; & Lt; User_translate.length (); ++ count_val; } Return 0; }  

I'm not sure that .length () is not working properly. Am I doing something wrong? Is there another way I can use to add the number of letters with spaces? Thank you.

  string str; Std :: getline (cin, str); Int len ​​= str.length ();  

In this way you can get the actual length of the sting in white space too.

std :: cin & gt; & Gt; Str ; As soon as the first white position appears in // string, the reading string will not be read as soon as possible.

As you would like to enter your string string is my name using the Std :: cin & gt; & Gt; Str; Only str = "my" will be archived.


Comments