Hello,
i have problem with size() function.
Whenever i want to count how many characters have string i typed from console, i got wrong value.
The problem is that size() counts characters to first space in typed string.
in code
string strNps ="Bla bla bla"
int i = strNps.size()
integer i gets correct value (11)
but in code
string strNps;
cin>>strNps;
int i = strNps.size();
integer i gets number of characters to first space - for example for typing "Bla bla bla" int i gets value 3.
The problem is that size() counts characters to first space in typed string.
No, it doesn't, as the first lines of your snippet demonstrate. Your problem is the >> operator. It uses whitespace as a delimiter, so cin >> strNps; reads input until it finds a whitespace and leaves the rest of the input in the stream. You want to use getline():