由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - some problems with "cin"
相关主题
有人能解释一下这段C++代码吗问一个C++的问题
how to let cin get enterEntity Extraction一般是用什么算法来实现呀?
A problem on string parsing (using either grep or perl)求助:script for commands (转载)
C++ Q13: InputAny good OCR engine?
Usage of Grep???help!!!我来贡献一个面试题吧
What language I should use?《Linux Essentials》英文文字版
perl: how to get the filename from the full path name请教一个字串提取的问题 (转载)
Help: How to extract the numberic value in a sentence?唉,看来scala已经废了
相关话题的讨论汇总
话题: cin话题: istream话题: int话题: problems话题: me
进入Programming版参与讨论
1 (共1页)
w*****j
发帖数: 49
1
here is a little script i wrote:
int main(){
int n;
if(!(cin>>n)){
int m;
cin>>m;
cout< }
}
if i type in a letter when it asks me to give a value to integer to n, it
won't let me input m, and simply print out 0, which i assumes is the value
of m. Anybody here is willing to help me out a little bit?
X****r
发帖数: 3557
2
This is how istream works: you try to extract a number from it by
"cin >> n", but the next character is not a part of any number,
so istream refuses to extract it. The rouge character is kept in
the istream, and the error state of this istream object is set to
"fail". To resume extracting numbers from this istream, you have
to do both of the following:
1) clear the "fail" state of the istream by calling "cin.clear()"
2) remove the bad character(s) from the stream. The easiest
way is to call "cin

【在 w*****j 的大作中提到】
: here is a little script i wrote:
: int main(){
: int n;
: if(!(cin>>n)){
: int m;
: cin>>m;
: cout<: }
: }
: if i type in a letter when it asks me to give a value to integer to n, it

w*****j
发帖数: 49
3
Thank you very much, it works.

【在 X****r 的大作中提到】
: This is how istream works: you try to extract a number from it by
: "cin >> n", but the next character is not a part of any number,
: so istream refuses to extract it. The rouge character is kept in
: the istream, and the error state of this istream object is set to
: "fail". To resume extracting numbers from this istream, you have
: to do both of the following:
: 1) clear the "fail" state of the istream by calling "cin.clear()"
: 2) remove the bad character(s) from the stream. The easiest
: way is to call "cin

1 (共1页)
进入Programming版参与讨论
相关主题
唉,看来scala已经废了Usage of Grep???help!!!
怎样把“jackie chan"的字样去掉? (转载)What language I should use?
请教改numpy array的dtypeperl: how to get the filename from the full path name
求思路:怎么快速收集全美主要research school 的教授名单?Help: How to extract the numberic value in a sentence?
有人能解释一下这段C++代码吗问一个C++的问题
how to let cin get enterEntity Extraction一般是用什么算法来实现呀?
A problem on string parsing (using either grep or perl)求助:script for commands (转载)
C++ Q13: InputAny good OCR engine?
相关话题的讨论汇总
话题: cin话题: istream话题: int话题: problems话题: me