字符串转化
来源:互联网 发布:个人数据 编辑:程序博客网 时间:2024/06/05 03:05
1 string to CString
CString.format("%s",string.c_str());
2 CString to string
string str(CString.GetBuffer(str.GetLength()));
3 string to char *
char *p=string.c_str();
4 char * to string
string str(char*);
5 CString to char *
strcpy(char,CString,sizeof(char));
6 char * to CString
CString.format("%s",char*);
CString的format方法是非常好用的。string的c_str()也是非常常用的,但要注意和char *转换时,要把char定义成为const char*,这样是最安全的。
以上函数UNICODE编码也没问题:unicode下照用,加个_T()宏就行了,像这样子_T("%s")
补充:
CString 可能是 CStringW/CStringA,在与 string 转换时,如果是 CStringW,还涉及编码转换问题。下面以 CStringA 来说明。
1 string to CString
CString.format("%s",string.c_str());
CStringA = string.c_str() 就可以了
2 CString to string
string str(CString.GetBuffer(str.GetLength()));
GetBuffer 有参数的话,可能导致内部的分配空间动作,要进行后续 ReleaseBuffer 操作。
string = CStringA
string = CStringA.GetBuffer();
3 string to char *
char *p=string.c_str();
4 char * to string
string str(char*);
5 CString to char *
strcpy(char *,CString,sizeof(char));
按照 3 风格,这里应该 char * = CStringA; 或者 char *p = CStringA.GetBuffer();
6 char * to CString
CStringA = char * 就可以了
7 CString转化为char *
CString filename
char * pNumber=new char[256];
WideCharToMultiByte(CP_ACP,0,filename,-1,pNumber,256,NULL,NULL );
char * pNumber=new char[256];
WideCharToMultiByte(CP_ACP,0,filename,-1,pNumber,256,NULL,NULL );
0 0
- 字符串转化
- 字符串转化
- 字符串转化
- 字符串转化
- 字符串转化
- 字符串转化
- 字符串转化
- 字符串转化
- 数字字符串转化字母字符串
- 字符串转化为日期
- 字符串转化为int
- 整数转化为字符串
- 数字转化成字符串
- Sql datetime 转化字符串
- 整数字符串转化
- C++ 字符串 相互转化
- 字符串到实数转化
- 字符串转化为数值
- 回文串判定 解法一
- jquery对象和javascript对象相互转换
- 上海交大施奇惠教授:循环肿瘤细胞(CTC)检测干
- 安装ORACLE时在Linux上设置内核参数的含义
- jQuery选择器课堂随笔
- 字符串转化
- 苹果关键字的讲解(@synthesize @dynamic)
- #define 宏名带参数
- Google's new "Android Things" OS hopes to solve awful IoT security
- 线程安全与不可重入函数
- ArcMapControl不显示矢量图层的问题
- angularjs分页查询
- eclipse svn SSL 错误
- muduo源码分析之事件处理器-Channel