现在的位置: 首页 > 综合 > 正文

c++中的类型转换和字符串相应操作函数

2012年11月30日 ⁄ 综合 ⁄ 共 590字 ⁄ 字号 评论关闭

1.int,double到CString的转化:
CString str;
int a;
double b;
str.Format("%d%f",a,b);

2.char*到CString的转化:
char *s = "this is a string";
CString str = _T(s);

3.CString到char*的转化:
CString str = _T("汉字也OK。");
//const char* s = (LPCTSTR)str;
char* s = str.GetBuffer();
str.ReleaseBuffer();
s=0;

4.const char*到int,double
int i = atoi("100");
double ii = atof("100.0");

CString可以加号连接char*字符串
用Append(_T("追加字符串"));
用Find(_T("查字符串,返回int型"));
用Insert(int index,_T("插入字符串"));
用GetLength()返回字符串长度;
用Right(int size)截取尾部长度的字符串
用Left(int size)截取头部长度字符串
配合使用Right,Left,Find可以截取特定位置的字符串

 

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/sworderandy/archive/2007/12/26/1968181.aspx

抱歉!评论已关闭.