如何在CIN中以C 的CIN中的所有读取为字符串
How to read in all whitespaces with cin in C++ into a string?
是一种令人费解的问题,但是是否可以从用户读取输入,而是让CIN在Newlines或Whitespaces上停止?例如,用户可以输入:
Hello w orld!
Hello World!
,我希望所有的空格和纽线字符输入到字符串中,只是用户的原始输入。有人可以告诉我如何在C 中做到这一点吗?谢谢。
您可以使用std :: getline为此:
#include <iostream>
#include <string>
int main()
{
std::string helloWorld;
std::getline( std::cin, helloWorld );
return 0;
}
相关文章:
- 从 cin 读取不会返回整个输入字符串
- 使用 cin 读取空行
- 为什么从 std::cin 读取输入后右括号字符的值有时不是")"?
- 如何从 cin 读取直到输入非数字内容?
- 如何从文件中读取,然后继续从cin读取?
- 使用 cin 读取大型输入时程序冻结
- 使用 cin 读取逗号分隔的整数对 (x,y) 和任意空格
- 从 cin 读取 PNG 文件
- 从cin读取不同类型的输入
- 将大写字母(从 cin 读取)更改为小写
- 如何超载CIN读取文件
- 多次从 std::cin 读取 -- Linux 和 Mac OS X 上的行为不同
- 如何清除cin读取的内容
- 我希望 cin 读取直到'n'但我无法使用 getline
- 如何终止从 cin 读取
- 将 getline 从 cin 读取到字符串流 (C++)
- 使用 cin 读取字符串时出错
- 如何使用 cin 读取带有空格的输入,直到到达制表符
- 是否可以从 cin 读取空字符串,并且仍然可以从 cin.good() 中获取 true
- 使用cin读取格式化输入