Hi,
Is there a simple library function I can use to read a single line from stdin in 1) C and 2) C++? Thanks in advance.
how to readline?
Moderator: Board moderators
1)
2)
Code: Select all
char buffer[maximum_size_of_input_line_you_expect + 1];
gets(buffer);
Code: Select all
string s;
getline(cin, s);
Using the magic of scanf:
Code: Select all
char line[MAX_LINE_LENGTH+1];
scanf("%.*[^\n]", MAX_LINE_LENGTH, line);