Answer the question
In order to leave comments, you need to log in
How does scanf work in pros?
how does scanf work in pros?
I need to ask for the input of a string in a loop at each iteration.
cin » s1
allows you to do this, but
scanf("%255[^\n]", s1)
only 1 time.
In addition, cin "eats" everything after a space.
Answer the question
In order to leave comments, you need to log in
I need to ask for the input of a string in a loop at each iteration.
cin » s1
allows you to do this, but
scanf("%255[^\n]", s1)
only 1 time.
char *p;
scanf("%m[^\n]\n", &p);
1. To enter a line, use std::getline.
2. Well, C++ has well-encapsulated strings, but C doesn't. Therefore, in C it is very difficult to get a string of unknown length from a stream.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question