-
cin
stupid question
if i wanted to cin a string
but the string consisted of multiple words, how would i do it
for instance
Code:
int main ()
{
char f[100];
cin >> f;
cout << f;
return 0;
}
wont do the job if i enter a string like Good morning everyone.
because it takes the space as a delimiter.
any ideas... i know this is a stupid question.. early morning mind isnt working :D
-
ignore question
i got it
cin.getline (f,100);
just in case anyone has the same question in the future. :)
-
using member function getline for char* type strings.
cin.getline(array,sizeof_array,delim_char='\n');
-
Or, for reading a line of input into a string type:
string text;
getline(cin, text, '\n');
Note that for both cin.getline() and getline(), you can read in multiple lines of text by changing the "delimiter" which is the 3rd parameter. If you use a '#' as the third parameter, input will continue until those functions find a '#' sign in the input, which you can insert after say the 5th line of input.