2024年3月29日发(作者:)
vc2005/2008与vc6.0头文件的变动
VC 2008-05-31 13:16:13 阅读136 评论0 字号:大中小 订阅
引子
The standard C headers names use the form name.h. The C++ versions of these headers are
named cname the C++ versions remove the .h suffix and precede the name by the letter c. Thec
indicates that the header originally comes from the C library. Hence, cctype has the same contents as
ctype.h, but in a form that is appropriate for C++ programs. In particular, the names defined in the cname
headers are defined inside the std namespace, whereas those defined in the .h versions are not.
C、传统 C++
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
//////////////////////////////////////////////////////////////////////////
标准 C++ (同上的不再注释)
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
//STL 双端队列容器
//异常处理类
//STL 定义运算函数(代替运算符)
//STL 线性列表容器
//STL 映射容器
//基本输入/输出支持
//输入/输出系统使用的前置声明
//基本输入流
//基本输出流
//STL 队列容器
//STL 集合容器
//基于字符串的流
//STL 堆栈容器
//标准异常类
//底层输入/输出支持
//字符串类
//STL 通用模板类
#include
#include
#include
using namespace std;
//////////////////////////////////////////////////////////////////////////
C99 增加
#include
#include
#include
#include
#include
#include
"今天突然想起来编个程序用一下命名空间,当我运行的时候才发现自己犯
了一个错误,预处理命令用了#include
C1083: 用无法打开包括文件:“iostream.h”: No such file or directory;
我把他改为#include
同的编译器厂商选用了不同的文件扩展名,引起所提供的类库的不同,所以带
来源代码的可移植性的限制。为了消除这些差别,C++标准适用的格式允许文件
名长度可以大于众所周知的8个字符,去除了扩展名。例如,用
#include
的C的头文件,是老的,是非模板化的。而没有.h的头文件是新的模板化的版
本,二者如果在程序中混用的话可能会带来问题。后面那个多加一行using
namespace std 两个的区别是所用到的库的不同。实际上是名字空间namespace
这个概念是在C++中才引入的,C中是没有的。所以在C中才没法用而已,实际
上C中也是需要类似的概念来解决名字命名问题的。 "
error C2065: 'cout' : undeclared identifier
2009-02-02 13:12
....(11) : error C2065: 'cout' : undeclared identifier
....(12) : error C2065: 'cin' : undeclared identifier
今天编译VC++的时候竟然出了两个错误,呵呵!仔细又一看发现挺衰的!
后来加入了预编译的 using namespace std;
或者是cout cin写成std::cin>>i;问题就解决了。
其实就是 Namespace的问题
Namespace是一个挺有趣的东西,它的引入是为了方便我们使用相同名字的变
量、常量、类(在第二章我们会接触类)或是函数。一个Namespace是这样定
义的:
namespace xxx //xxx是namespace的名字
{
}
在这里可以像平常一样定义各种东西
以后要使用某个namespace中的东西,比如说xxx中的aaa,像这样:xxx::aaa
即可。不过这样好像挺麻烦的----平白无故就多出了一个"xxx::"。于是有了
"using namespace xxx;"这种语句,可以帮你省下这几个字符。记住,"using
namespace"也只是在最紧挨它的一对{和}符号内起作用,在所有函数之外执行的
这条语句才在整个文件中有效。注意:
namespace s1
{
}
namespace s2
{
}
void main( )
{
using namespace s1;
using namespace s2;
//a=a+1; //这句是错误的!因为编译器此时无法确定a在哪个
float a=0;
int a=0;
namespace
}
那么我们在第一个程序中为何要using namespace std;呢?其实也是为了把
"std::cout"变成简洁一点的"cout"。
s1::a = s2::a + 1; //这样就是正确的


发布评论