作者热门文章
- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我正在努力从 C++ 控制台读取字符。这是我尝试做的:
char x;
char y;
char z;
cout<<"Please enter your string: ";
string s;
getline(cin,s);
istringstream is(s);
is>> x >> y >> z;
问题是如果用户输入像这样的“1 20 100”:
x will get 1
y will get 2
z will get 0
我要得到的是x = 1; y = 20; z = 100;
有人有建议吗?
最佳答案
你不想读取字符而是整数。
int x;
int y;
int z;
cout<<"Please enter your string: ";
string s;
getline(cin,s);
istringstream is(s);
is>> x >> y >> z;
关于c++ - 如何在 C++ 中从控制台读取字符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2557638/
我是一名优秀的程序员,十分优秀!