於#include之後緊接著打:
using std::cout; using std::cin; using std::endl;如此可以直接使用cout, cin, endl,且指定到std::。
又若是整個程式都要使用std的命名空間(namespace)的話,可以打這行:
using namespace std;
完整的範例如下:
#include <iostream>
using namespace std;
int main()
{
int a;
cout << "Hello Heron!" << endl;
cout << "a >> ";
cin >> a;
cout << "a = " << a << endl;
return 0;
}
No comments:
Post a Comment