关于读入一行字符数组且其中包含空格的解决方案(Solution for reading in a line of character array with spaces)

比如读入以下句子,如果用只会读入第一个空格之前的字母”Hello”.

scanf("%s",str);
Hello World Here I Come

以往惯用的方法是,但C++11取消了,故跟随时代。

gets()

新的方式为 ,表示遇到回车停止。
还有其他一些方法,欢迎移步大神博客c/c++中读入字符串(包含空格)

scanf("%[^\n]",str);
————————

For example, if you read the following sentences, you will only read the letter “hello” before the first space

scanf("%s",str);
Hello World Here I Come

The usual method in the past is, but C + + 11 is cancelled, so it follows the times.

gets()

The new method is, which means that the carriage return stop is encountered.
There are other methods. You are welcome to read the string (including spaces) in C / C + +

scanf("%[^\n]",str);