In one part of my code I should get characters one by one. It's easy but my question is how can I add these characters one by one into a string. Note that I don't know how many characters I will get.
It is important that just the characters be copied in string. In the other words, I want to generate words from characters until the character is not equal to ' '
or '\n'
.
the wrong code that I wrote is:
char c;
string str = NULL;
cin.get(c);
while (c != " ")
{
str += c;
cin.get(c);
}
cout << str ;
For example, if character c
would be 'H'
at first and then be 'i'
,
I want to the string str to be "Hi"
on cout
!