1 #include <iostream>
 2 #include <string>
 3 using namespace std;
 4 int main()
 5 {
 6     int number;
 7     while (cout << "Enter a number : " && !(cin>>number))
 8     {
 9         cin.clear();
10         string line;
11         getline(cin, line);
12         cout << "I am sorry, but '" << line << "' is not a numbern";
13     }
14     cout << "I got your number : " << number << endl;
15 
16 
17     return 0;
18 }

 1 #include <iostream>
 2 #include <string>
 3 using namespace std;
 4 int main()
 5 {
 6     int number;
 7     while (cout << "Enter a number : " && !(cin>>number))
 8     {
 9         cin.clear();
10         char ch;
11         do
12         {
13             cin.get(ch);
14         } while(ch != 'n');
15         cout << "Sorry Please enter a number : " << endl;
16     }
17     cout << "I got your number : " << number << endl;
18 
19     return 0;
20 }

 

 

内容来源于网络如有侵权请私信删除
你还没有登录,请先登录注册
  • 还没有人评论,欢迎说说您的想法!

相关课程

3788 8.82元 9.8元 9折