E
E
EmachinesDIMA2018-10-19 14:16:31
C++ / C#
EmachinesDIMA, 2018-10-19 14:16:31

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

3 answer(s)
J
jcmvbkbc, 2018-10-19
@jcmvbkbc

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.

But this scanf -- allows you to do this as many times as you like:
And this one allows you to enter a string of unknown length in advance:
char *p;
scanf("%m[^\n]\n", &p);

M
Mercury13, 2018-10-19
@Mercury13

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.

R
rPman, 2018-10-21
@rPman

charbuf[256];
fscanf(stdin,"%255[\n]",buf);
The scanf markup language is unusual, but it allows you to parse strings very quickly (for example, simple csv without escaped quotes and separators in strings containing, for example, numbers).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question