int 转 CString:
CString.Format("%d",int);
...............................
string 转 CString
CString.format("%s", string.c_str());
用c_str()确实比data()要好.
.......................................
char* 转 CString
CString.format("%s", char*);
CString strtest;
char * charpoint;
charpoint="give string a value";
strtest=charpoint; //直接付值
...................................................................
CString 转 int
CString ss="1212.12";
int temp=atoi(ss); //atoi _atoi64或atol
将字符转换为整数,可以使用atoi、_atoi64或atol。
int int_chage = atoi((lpcstr)ss) ;
或:
CString str = "23";
UINT uint;
sscanf(str, "%d", uint);
..............................
string 转 int
..............................
char* 转 int
#include <stdlib.h>
int atoi(const char *nptr);
long atol(const char *nptr);
long long atoll(const char *nptr);
long long atoq(const char *nptr);
...................................................................
CString 转 string
string s(CString.GetBuffer());
GetBuffer()后一定要ReleaseBuffer(),否则就没有释放缓冲区所占的空间.
..........................................
int 转 string
..........................................
char* 转 string
string s(char *);
你的只能初始化,在不是初始化的地方最好还是用assign().
...................................................................
CString 转 char *
CString strtest="wwwwttttttt";
charpoint=strtest.GetBuffer(strtest.GetLength());
CString str="aaa";
char* ch;
ch=(char*)(LPCTSTR)str;
..........................................
int 转 char *
在stdlib.h中有个函数itoa()
itoa的用法:
itoa(i,num,10);
i 需要转换成字符的数字
num 转换后保存字符的变量
10 转换数字的基数(进制)10就是说按照10进制转换数字。还可以是2,8,16等等你喜欢的进制类型
原形:char *itoa(int value, char* string, int radix);
实例:
#include "stdlib.h"
#include "stdio.h"
main()
{
int i=1234;
char s[5];
itoa(i,s,10);
printf("%s",s);
getchar();
}
..........................................
string 转 char *
char *p = string.c_str();
string aa("aaa");
char *c=aa.c_str();
string mngName;
char t[200];
memset(t,0,200);
strcpy(t,mngName.c_str());
...................................................................
标准C里没有string,char *==char []==string
CString.Format("%d",int);
...............................
string 转 CString
CString.format("%s", string.c_str());
用c_str()确实比data()要好.
.......................................
char* 转 CString
CString.format("%s", char*);
...................................................................
CString 转 int
将字符转换为整数,可以使用atoi、_atoi64或atol。
int int_chage = atoi((lpcstr)ss) ;
或:
..............................
string 转 int
..............................
char* 转 int
...................................................................
CString 转 string
..........................................
int 转 string
..........................................
char* 转 string
...................................................................
CString 转 char *
CString转换 char[100]
char a[100];
CString str("aaaaaa");
strncpy(a,(LPCTSTR)str,sizeof(a));
..........................................
int 转 char *
}
..........................................
string 转 char *
char *p = string.c_str();
...................................................................
标准C里没有string,char *==char []==string
可以用CString.Format("%s",char *)这个方法来将char *转成CString。要把CString转成char *,用操
作符(LPCSTR)CString就可以了。
cannot convert from 'const char *' to 'char *'
const char *c=aa.c_str();
string.c_str()只能转换成const char *
const char *c=aa.c_str();
string.c_str()只能转换成const char *