MFC 与 C++ 类型转换

C++ 中到的类型转换很多,先记录下来,多了写成一个类

1、CString转int

1 CString cNum="9527";
2 int iNum = 0;
3 iNum=atoi(LPCTSTR(cNum));
View Code

 2、int转CString

1 int iNum = 2211;
2 CString strNum = "";
3 strNum.Format("%d", iNum);
View Code

3、string转CString

1 string str = "hello";
2 CString cstr = "";
3 cstr = str.c_str();
View Code

4、CString转string

1 CString cstr = "hello";
2 string str = "";
3 str = cstr.GetBuffer(0);
4 cstr.ReleaseBuffer();
View Code

 

posted on 2014-04-30 11:29  百足Coder  阅读(162)  评论(0编辑  收藏  举报

导航