|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本人是C++菜鸟,今天在编写程序时发现using namespace std; 与 std::存在差异,如果用如下代码能够正确实现。
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
double i = 0.0;
cout << "please enter a number!" << endl;
cin >> i;
for (int j=1; j<6; j++)
{
cout.precision(j);//控制浮点数的输出精度!
cout << i << endl;
}
return 0;
}
但是当不用using namespace std;而改为用std::cout的形式时VC++6.0会报错,错误如下:
d:\程序\example\cout\out.cpp(7) : error C2653: 'ios' : is not a class or namespace name
d:\程序\example\cout\out.cpp(7) : error C2065: 'fixed' : undeclared identifier
d:\程序\example\cout\out.cpp(8) : error C2653: 'ios' : is not a class or namespace name
d:\程序\example\cout\out.cpp(8) : error C2065: 'showpoint' : undeclared identifier
d:\程序\example\cout\out.cpp(12) : error C2065: 'endl' : undeclared identifier
Error executing cl.exe.
out.obj - 5 error(s), 0 warning(s)
有没有高手知道是为什么会这样?
|
|