I'm trying my hand at reading from standard input and having little luck. In particular, I would like to be able to do the rough equivalent of C++'s:

cin >> myString;

As opposed to reading the whole line.

I attempted to do this with readf:

string result;
readf(" %s ", &result);

However this does not seem to do the trick. If I enter "Hello\n" on the terminal, it keeps waiting for input. By contrast, if I enter "Hello program", it correctly identifies "Hello" as the 'result'.

Thus, contrary to what I've been reading, the trailing space seems to only account for space characters, not general whitespace.

I presume that I'm missing something obvious, any ideas?


Thanks in advance!

Reply via email to