cstring、string、wstring、int、char*、tchar、 int、dword等相互转换代码输出测试
#include <string>
#include <tchar.h> // _TCHAR
#include <stdlib.h>
#include <iostream>
#include <atlstr.h> //Cstring
#include <atlconv.h> //W2A宏
#include <xstring> using namespace std; int _tmain(int argc,_TCHAR* argv[])
{
/**********string->cstring ***********/
//setlocale(LC_ALL, "Chinese-simplified");
//wcout.imbue(locale("chs"));
//std::string str = "123456!";
//CString cstr = _T("");
//方式一
//cstr.Format(_T("%s"),str.c_str());
//方式二
//for(int i = 0; i < (int)str.length(); ++i)
//{
// cstr += str[i];
//}
//方式三
//cstr = str.c_str();
//wcout << cstr << endl; /************ cstring->string **************/
//方式一
//CString cstr1 = _T("this is cstring!");
//string str1 = "";
//str1 = cstr1.GetBuffer();
//cstr1.ReleaseBuffer();
//方式二
//for (int i = 0; i < cstr1.GetLength(); ++i)
//{
// str1 += cstr1[i];
//}
//方式三 W2A宏
//str1 = W2A(cstr1);//用法还没弄懂,需要加入一些文件头 或宏定义 ??? //cout << str1 << endl; /************* string-> char*************/
//string str2 = "this is string2!";
//方式一
//char *p = (LPSTR)str2.c_str();
//方式二
//char t[200];
//memset(t, 0,200);
//strcpy(t,str2.c_str());
//方式三 出现warning C4305: “=”: 从“int”到“char”截断 ???
//char *pc = new char[str2.length() + 1];
//pc[str2.length()] = '/0';
//for (int i = 0; i < str2.length(); ++i)
//{
// pc[i] = str2[i];
//}
//pc[str2.length()] = '/0';
//cout << pc << endl; /****************** char*->string ******************/
//char *pch = "this a char!";
//方式一 只能用作初始化
//string str3(pch);
//方式二 assign()赋值
//string str3;
//str3.assign(pch);
//cout << str3 << endl; //string是ansi编码字符char
//TCHAR是unicode编码字符wchar_t
/*********** string -> TCHAR* *********/
//使用MultiByteToWideChar()函数 /*********** TCHAR* ->string *********/
//使用 WideCharToMultiByte()函数 /**************** string 和char*转int ******************/
//int atoi(const char *nptr);
//long atol(const char *nptr);
//long long atoll(const char *nptr);
//long long atoq(const char *nptr); /*******************int转char*和string************************/
//使用itoa();itoa(i,str,10); /******************* wstring转Csting *****************/
//wstring wstr = L"this a wstring!你好啊";
//CString cstr4 = _T("");
//cstr4 = wstr.c_str();
//cout << cstr4 << endl; /******************* Csting ->wstring *****************/
//CString cstr5 = _T("this a cstring5!");
//wstring wstr5 = L"";
//wstr5 = cstr5.AllocSysString();
//wcout << wstr5 << endl; /********* Cstring转char* *************/
//CString cstr6 = _T("this cstring6!");
//char* pch6 = "";
//pch6 = cstr6.GetBuffer();
//cout << pch6 << endl;
//cstr6.ReleaseBuffer(); /************ char *转Cstring **********/
//char pch[20] = "this a char* !";
//CString str7 = _T("");
//str7.Format("%s",pch);
//cout << str7 << endl; /*********** TCHAR -> char ************/
//TCHAR *pTch = _T("this a TCHAR");
//int nLength = 2 * strlen(pTch);
//char* pCh = new char[nLength + 1];
//memset(pCh,0, nLength + 1);
//strcpy(pCh, pTch);
//cout << pCh << endl; /*********** char转tchar ************/ system("pause");
return ;
}
cstring、string、wstring、int、char*、tchar、 int、dword等相互转换代码输出测试的更多相关文章
- Linux基本数据类型大小——int,char,long int,long long int
转自:http://paddy-w.iteye.com/blog/1403217 在Linux操作系统下使用GCC进行编程,目前一般的处理器为32位字宽,下面是/usr/include/limit.h ...
- CString string char* char 之间的字符转换(多种方法)
在写程序的时候,我们经常遇到各种各样的类型转换,比如 char* CString string 之间的互相转换.首先解释下三者的含义. CString 是一种很有用的数据类型.它们很大程度上简化了MF ...
- MFC中cstring,string和char[]的相互转化
int 转 CString:CString.Format("%d",int);...............................string 转 CString CSt ...
- 计算机基础--Java中int char byte的关系
计算机基础--Java中int char byte的关系 重要:一个汉字占用2byte,Java中用char(0-65535 Unicode16)型字符来存字(直接打印输出的话是字而非数字),当然要用 ...
- unicode下各种类型转换,CString,string,char*,int,char[]
把最近用到的各种unicode下类型转换总结了一下,今后遇到其他的再补充: 1.string转CString string a=”abc”; CString str=CString(a.c_str() ...
- VC++中的CString、char、int类型转换
1.如何将CString类型的变量赋给char*类型的变量 方法一:GetBuffer函数 使用CString::GetBuffer函数. char *p; CString str=&quo ...
- QString, string, int, char* 之间相互转换
这三种数据类型在实际运用中经常需要互相转换,那么这里小结下它们之间的转换方法: - Qstring & string Qt中封装的类十分强大,其成员函数数量之多比STD有过之而无不及,许多程序 ...
- [转] java中int,char,string三种类型的相互转换
原文地址:http://blog.csdn.net/lisa0220/article/details/6649707 如何将字串 String 转换成整数 int? int i = Integer.v ...
- java中int,char,string三种类型的相互转换
如何将字串 String 转换成整数 int? int i = Integer.valueOf(my_str).intValue(); int i=Integer.parseInt(str); 如何将 ...
随机推荐
- 【WPF】ScrollViewer无法滚动的问题
还需要给ScrollViewer注册一个鼠标滚轮事件! XAML: <ScrollViewer x:Name="scrollViewer" Width="950&q ...
- HTML资料——做网页时遇到的
HTML <meta> 标签 浏览器支持 IE Firefox Chrome Safari Opera 所有浏览器都支持 <meta> 标签. 定义和用法 ...
- Mac安装wget
Mac安装wget wget版本: wget-1.17 参考来源: Mac OS 安装Wget 給Mac添加wget功能 The Wget package for Mac http://brew.sh ...
- Spring引入配置文件
1.spring.xml加载映射的配置配置文件 <!--采用这种方式简化配置文件--> <context:property-placeholder location="cl ...
- SGU 120 Archipelago (简单几何)
120. Archipelago time limit per test: 0.25 sec. memory limit per test: 4096 KB Archipelago Ber-Isla ...
- Linux 设置 LD_LIBRARY_PATH
在Linux下,如果自己写好一个动态链接库,需要在其他程序里调用,则需要让这些程序能找到这个动态链接库,如果设置的不对,就会出现类似的错误: error : cannot open shared ob ...
- opencv3.2 dnn 图像分割
下载 http://dl.caffe.berkeleyvision.org/fcn32s-heavy-pascal.caffemodel 在opencv_contrib-3.2.0/modules/d ...
- window,centos双系统坏了
在centos中格式化SD卡的时候,操作错误,误将windows系统C盘的给格式化了.C盘是ntf格式的,现在却变为了fat32的格式. 重启系统,发现还是可以进入到centos,但是window进入 ...
- 第二百八十三节,MySQL数据库-MySQL存储过程
MySQL数据库-MySQL存储过程 MySQL存储过程,也就是有点像MySQL函数,但是他与MySQL函数是有区别的,后面会讲到函数,所以注意区分 注意:函数与存储过程的区别 存储过程是:CREAT ...
- e670. 缓冲图像转换为图像
// This method returns an Image object from a buffered image public static Image toImage(BufferedIma ...