小弟是C++新生,近日看到有关“命名空间”的资料,被解释为将程序库名称封装起来的方法,可以避免和应用程序发生命名冲突的问题。我按它给的例程创建了一个Win32 Console Application运行很顺利,但当把“using namespace std;”这一句去掉,程序就编译不过去了,但我在一般的MFC AppWizard(exe)创建的程序中并没有找到“using namespace std;”这一句,而且程序运行平稳,为什么会这样?不知哪位“大虾”能指教一二。
解决方案 »
- 程序错误还是其他问题?帮忙看一下!(源码已经给出)问题解决马上结帖……
- 怎样实现按住按钮的时候做某事?
- * 编程经验: CtreeCtrl 分为2层, 第一层的itemdata用 struct A, 第二层itemdata用 struct B, 之后如何GetItemData正确呢?
- 300分求助。想做一个语音识别的系统,只要能识别0-9这十个数字即可。
- 在MFC的CSOCKET下面怎么获得发消息过来的客户端的IP?在线等,马上结!
- 请问滑动条控件怎样改变背景色
- 求图象的漩涡/螺旋变换算法。
- 谁有有关矢量字体的资料,想研究矢量字体,中文英文皆可,高分酬谢
- 我想要一个能显示bmp,jpg等图象格式的控件,哪位朋友能给我一个吗?
- 关于gettooltip
- 请问如何从类模板继承一个新类?
- 这个问题太典型了,我为此预备了800分,随时加上,决不食言,斑竹也来关心一下,我这是第三贴了,再无人问津我只好放弃VC了.........
如果你用了#inlcude <*>就要用。
比如#include <iostream>
using namespace std;
#include<iostream.h>
#include<string.h>
//using namespace std;
int main()
{
string user_name;
cout<<"Please enter your first name:";
cin>>user_name;
cout<<'\n'
<<"Hello,"
<<user_name
<<"...and goodbye!\n";
return 0;
}
#include<iostream>
#include<string>
using namespace std;
int main()
{
string user_name;
cout << "Please enter your first name:";
cin >> user_name;
cout << '\n' <<"Hello," <<user_name <<"...and goodbye!\n";
return 0;
}或者这么写:
#include<iostream>
#include<string>int main()
{
std::string user_name;
std::cout << "Please enter your first name:";
std::cin >> user_name;
std::cout << '\n' <<"Hello," <<user_name <<"...and goodbye!\n";
return 0;
}
都可以编译通过。
这个程序是在Essential c++里的,我也看不懂呀,基础太差,唉~~~~