首页 > 试题广场 >

重新编写下面的代码,使之使用using声明,而不是using

[问答题]
重新编写下面的代码,使之使用using声明,而不是using编译指令。
#include <iostream>
using namespace std;
int main()
{
     double x;
     cout << "Enter value: ";
     while (! (cin >> x) )
     {
            cout << "Bad input. Please enter a number: ";
            cin.clear();
          while (cin.get() != '\n')
                continue;
      }
      cout << "Value = " << x << endl;
      return 0;
}


推荐
下面是修改后的代码:
#include <iostream>
int main()
{
     using std::cin;
     using std::cout;
     using std::endl;
       double x;
       cout << "Enter value: ";
       while (! (cin >> x) )
       {
             cout << "Bad input. Please enter a number: ";
             cin.clear();
           while (cin.get() != '\n')
                 continue;
        }
        cout << "Value = " << x << endl;
        return 0;
}


发表于 2018-05-08 08:40:09 回复(0)