I am trying to scan in 1-3 words from the user into a string. However, Only the first word will scan.
相关问题
- Multiple sockets for clients to connect to
- What is the best way to do a search in a large fil
- glDrawElements only draws half a quad
- Index of single bit in long integer (in C) [duplic
- Equivalent of std::pair in C
scanf
stops reading from the stream when a space is encountered. You need to use getline instead.One possibility is to use a scan set conversion instead of a string conversion:
Much like
fgets
, this reads up to the end of the line rather than stopping at the first white-space character.