【发布时间】:2014-11-18 21:02:13
【问题描述】:
我正在编写一个程序,此时只接受 int 作为用户输入,如果不是,请继续询问用户直到获得正确的整数。下面是代码:
cout << "enter two integers: " << endl;
string input1, input2;
cin >> input1;
cin >> input2;
while (//if they are not integers)
...//ask again
如你所见,我使用字符串来存储输入,但我不知道如何检查这个字符串是否只包含一个整数。
【问题讨论】:
-
这当然不是字面上的重复,但您的问题的答案以及要考虑的代码都显示在那里。
标签: c++