CString转const char
CString转换成const char 需要考虑一个因素: 你使用是否为unicode
不使用unicode:
CString Cstr("aaaaaaa");
const char*
str;
str=Cstr.GetBuffer(sizeof(Cstr));
如果你在用的是unicode,那个这句话就会报错,提示char无法转换成为wchar_t*
使用unicode:
CString Cstr("aaaaaaa");
那么CString里面存储的是wchar_t*,而不是char*。
还要用其他的函数:
const wchar_t* wstr = ( LPCTSTR )Cstr;
//一定得是unicode,否则这句话会错的
char str[ 20 ] = { 0 };
wcstombs( str, wstr, wcslen( wstr ) );
注意:如果CString里有中文的话,在wcstombs前后还应加这么两句:
setlocale( LC_ALL, "chs" );
wcstombs( str, wstr, wcslen( wstr ) );
setlocale( LC_ALL, "C" );
CString转const char的更多相关文章
- CString转换为const char*
CString str=_T("这是我的测试程序.");// 先得到要转换为字符的长度const size_t strsize=(str.GetLength()+1)*2; // ...
- 终于搞定在VS2010中将CString转换为const char*
最近碰到了CString 转 const char *的问题. 以前只要简单的一个强制转换就OK了,可现在是不行了,搜索了很多资料,终于搞定,主要是Unicode和ANSI的问题,只要做一个转换就可以 ...
- VS2010中将CString转换为const char*
最近碰到了CString 转 const char *的问题. 以前只要简单的一个强制转换就OK了,可现在是不行了,搜索了很多资料,终于搞定,主要是Unicode和ANSI的问题,只要做一个转换就可以 ...
- 【DEBUG】不能将参数 1 从“CString”转换为“const char *”
1. 在vc6.0下用CString str;num = atoi(str);就可以顺利取到num: 但是同样代码拿到vs2008就报错,error C2664: "atoi": ...
- VS2017出现不存在从"CString"到"const char*"的适当转换函数
出现不存在从CStrign到const char*的转换,可以将项目属性的字符集设置从"使用Unicode字符集“转换为”使用多字字符集“. 点击”项目“----“属性”----“配置属性” ...
- CString 转化成 const char* 类型
写程序的时候经常会遇到无法将“CString”转换为“const char *”的错误,这里我找到了一个解决办法,与大家分享下: CString cs = _T("); ) * ; char ...
- CString、string、const char*的相互转换
环境:vs2010 1.CString转string //第一种方式: CString str = _T("CSDN"); USES_CONVERSION; std::string ...
- VS2013 MFC C++ CString ,const char , char, string 类型转换
VS2013 测试 以下测试加入头文件: # include <string>#include <cstdlib>using namespace std; //-------- ...
- CString转换成char *字符串问题
buf = (LPSTR)(LPCTSTR)str; ==> buf 显示的是第一个字符 strcpy(pNumber,strNumber); ==> e ...
随机推荐
- Spring IOC基础回顾 — 组件扫描和装配
目录 注解形式配置应用IOC 1. 组件自动扫描 2. 组件依赖:为bean添加注解,实现自动注入 3. Spring IOC应用小结 注解形式配置应用IOC 在类定义.方法定义.成员变量定义前使用, ...
- 百度跨域搜索demo
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...
- 【AT3611】Tree MST
题目 这个题的输入首先就是一棵树,我们考虑一下点分 我们对于每一个分治重心考虑一下跨过这个分治重心的连边情况 就是把当前分治区域内所有的点向距离分治重心最近的点连边 考虑一下这个算法的正确性,如果我们 ...
- 2018-8-10-VisualStudio-2017-项目格式-自动生成版本号
title author date CreateTime categories VisualStudio 2017 项目格式 自动生成版本号 lindexi 2018-08-10 19:16:52 + ...
- opencv编译:The CXX compiler identification is unknown The C compiler identification is unknown
opencv编译:The CXX compiler identification is unknown The C compiler identification is unknown 解决方法: F ...
- 【HZOI2015】帕秋莉的超级多项式
题面 题目分析 超级模板题: 多项式乘法 多项式求逆 多项式开根 多项式求导 多项式求积分 多项式求对数 多项式求自然对数为底的指数函数 多项式快速幂 代码实现 #include<iostrea ...
- leetcode-86-分割链表
题目描述: 方法一: # Definition for singly-linked list. # class ListNode: # def __init__(self, x): # self.va ...
- centos6 nginx安装好以后,添加拓展ssl
前言 安装nginx的时候,只是执行最简单的安装,--user=nobody --group=nobody --prefix=/usr/local/nginx_1.8.1,没有安装http_ssl_m ...
- Android基础控件TextView
1.常用属性 <TextView android:id="@+id/text11" //组件id android:layout_width="match_paren ...
- PAT甲级——A1093 Count PAT's【25】
The string APPAPT contains two PAT's as substrings. The first one is formed by the 2nd, the 4th, and ...