字符串之间以及与int float double转换

1 CString 与string char*转换

2 string 与 int  之间的相互转换

3 int float =>字符数组char a[]之间的相互转换


1 CString 与string char*转换  以及LPCTSTR LPTSTR

CString 是MFC中处理字符串的

string是c++的

string(a 表示)->CString(s表示):  string a;

   CString s(a.c_str());

CString->string : 

   #include "altconv.h"

   string a; CString s;

    CT2A s1(s) ; 

   a=s1;

   string->const char *   

   const char* ch=a.c_str();

 

L表示long P表示point 指针 C表示常量 T表示宏,在编译时确定字符串时以何种不同的编码方式 (ANSI UNICODE);STR 表示字符串

 

LPCTSTR=const TCHAR* { 在ANSI编码下       =const char*=          LPCSTR

                    { 在unicode编码下  =const wchar*=   LPCWSTR

LPTSTR =TCHAR*  { 在ANSI编码下       =char*=          LPSTR

                 { 在unicode编码下  =wchar*=  LPWSTR

 

CString与LPCTSTR 通用,因为CString重载

    CString s1;LPCTSTR s2;

    s1=s2;

    s2=(LPCTSTR)s1;

 

2 string《=》 int 转换

    string s;

   int t=_ttoi(s); atoi(s);

   CString s;  

   s.Format(_T("%d"),t);


int=》string

#include<stream>

stringstream ss; int i; string str;

ss.clear();  

ss << i;  (不能为float,否则str为空!~)

ss >> str;  


3 int float char=》char a[] 使用sprintf 

char a[255];

strcpy(a,"");//或者memset(a,'\0',255);

char *s ="e:\\";

int i=0;

sprintf(a,"%s%d%s",s,i,".jpg");



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值