string与CString分得清么?

首先说string的头文件

1、<string>

包装了std的C++头文件

2、<string.h>

旧的C头文件

3、<cstring.h>

旧C头文件的std版本,切记,这不是cstring的头文件

详见effectivec++ 的第49条

再说cstring的头文件

注:VC9编译环境下

1、<atlstr.h>

非MFC版本,控制台程序就用这个

 

<afx.h>、<afxcoll.h>都可以。//要在项目->属性->常规里设置为使用MFC(动/静).

 

 

2、<afxstr.h>// only be used in MFC projects.

MFC版本,需要链接MFC的dll或静态库。网上很多人说要包含<afx.h>,<afx.h>包含的东西就比较多了CObject及其派生类,还有文件类、时间类、异常类、字符串类等等(700多行的位置包含了afxstr.h),如果仅仅需要cstring的话,包含<afxstr.h>就够了。

<afx.h>中的预处理

#ifdef _DLL

#ifndef _AFXDLL

#error Building MFC application with /MD[d](CRT dll version) requires MFC shared dll version. Please #define _AFXDLL or donot use /MD[d]

#endif

#endif

<afxstr.h>中的预处理

#ifndef _AFX

#error afxstr.h can only be used in MFC projects.  Useatlstr.h

#endif

注意上面的#error,大意就是这个头文件是在MFC工程里用的。


在VC中使用string一般都要用:

#include<iostream>#include<string> //string类需要用到的头文件using namespace std;
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值