c/c++中的各种字符串转换
一:CString 和 *char 的转换:
1:CString -> *char
1)CString转化为*char可以使用CString中的GetBuffer()函数,具体如下:
CString string1 = _T("string");
char *str = string1.GetBuffer();
注意的是,在GetBuffer后要使用ReleaseBuffer以更新对象内部数据,否则会发生不可意料的意外。
2)可以使用强制转换。
CString string1 = _T(“string”);
char *str = (LPTSTR)(LPCTSTR)string1;
3)也可使用函数strcpy实现转换。
4)使用CString的GetAt()函数:
CString string1 = _T("string");
char *str = string1.GetAt(0);
即获取下标为0的字符。
2:*char -> CString
1)使用format函数:
char *str = "string";
CString string1;
string1.format("%s",str);
2)同样也可以强制转换:
char *str = "string";
CString string1(str);
二:*char 与 int 的转换
1:*char -> int
1)使用atoi()函数:
char *val = "12345";
int num = atoi(val);
2:int -> *char
1)使用itoa()函数:
int num = 12345;
char buf[5];
itoa(buf, num, 10);
itoa()函数中后面10代表十进制。
2)使用sprintf()函数:
int num = 12345;
char buf[6];
sprintf(buf, "%d", num);
......
c/c++中的各种字符串转换的更多相关文章
- js中把JSON字符串转换成JSON对象最好的方法
在JS中将JSON的字符串解析成JSON数据格式,一般有两种方式: 1.一种为使用eval()函数. 2. 使用Function对象来进行返回解析. 第一种解析方式:使用eval函数来解析,并且使用j ...
- VC++编程中常用的字符串转换函数
VC++编程中经常遇到不同编码编码的字符串之间需要转换的情况,以下简单提供几个不同编码字符串之间的转换函数: ANSI 字符串和Unicode字符串之间的转换 //Convert wide char ...
- C#中,JSON字符串转换成对象。
在前台提交(post)的数据中.除了强类型的数据外,还有一个额外的json数据提交 在这里我的办法是,在前台把json对象转换成字符串,然后提交. 测试demo 前台: @using(Html.Beg ...
- mysql中如何把字符串转换成日期类型
select date_format('2013-03-09','%Y-%m-%d'); select date_format('2013-03-09','%y-%m-%d'); select STR ...
- 苹果浏览器和ios中,时间字符串转换问题
背景:在开发PC端项目和小程序时,遇到过一个时间字符串转化问题,在苹果浏览器和ios微信客户端里,"2018-10-15 18:20" 以 字符"-"拼接的时间 ...
- VC++中如何将字符串转换成整型数字
原文:http://blog.csdn.net/yongf2014/article/details/47071663 注意: atoi函数是c的函数,它的输入参数是char *类型. 你声明了stri ...
- MYSQL中日期与字符串间的相互转换
一.字符串转日期 下面将讲述如何在MYSQL中把一个字符串转换成日期: 背景:rq字段信息为:20100901 1.无需转换的: SELECT * FROM tairlist_day WHERE rq ...
- C#中对象,字符串,dataTable、DataReader、DataSet,对象集合转换成Json字符串方法。
C#中对象,字符串,dataTable.DataReader.DataSet,对象集合转换成Json字符串方法. public class ConvertJson { #region 私有方法 /// ...
- [转]JS中对象与字符串的互相转换
原文地址:http://www.cnblogs.com/luminji/p/3617160.html 在使用 JSON2.JS 文件的 JSON.parse(data) 方法时候,碰到了问题: thr ...
随机推荐
- JSON 之FastJson解析
http://blog.sina.com.cn/s/blog_7ffb8dd501013qas.html 一.阿里巴巴FastJson是一个Json处理工具包,包括“序列化”和“反序列化”两部分,它具 ...
- PKU Online Judge 1054:Cube (设置根节点)
1054:Cube 总时间限制: 1000ms 内存限制: 131072kB 描述 Delayyy君很喜欢玩某个由Picks编写的方块游戏,游戏在一个由单位格组成的棋盘上进行. 游戏的主角是一 ...
- [Practical Git] Configure global settings with git config
You can set up global "git config" settings that apply to all git projects on your system. ...
- interactive_timeout和wait_timeout(
mysql> show variables like "%timeout%"; +-----------------------------+----------+ | Va ...
- js之parentElement属性
<html> <head> </head> <body> <form name="a "> <table name ...
- 多台Linux服务器SSH相互访问无需密码--转
一.环境配置 1.系统:CentOS release 5.6 IP:192.168.4.200 主机名:JW01 2.系统:CentOS release 5.9 IP:192.168.4. ...
- Database API
Database API Introduction Basic Usage Selects Joins Aggregates Raw Expressions Inserts Updates Delet ...
- Android更改imagebutton为纯色方法
我的imagebutton所用的背景png图片是灰色的,但是我想让他显示出来是白色的按钮,如果用ps去一个个填充不太现实,那有没有什么办法去通过xml里的属性改变背景颜色呢? 一开始我用了网上的方法 ...
- SQL中N $ # @的作用
declare @sql nvarchar(4000) set @sql= N'select @TotalRecords=count(*) from ' + N'(' + @sqlFullPopula ...
- 关于Git远程版本库
Git作为分布式版本库控制系统,每个人都是本地版本库的主人,可以在本地的版本库中随心所欲的创建分支和里程碑. 当需要多人协作时,问题就出现了: 1.如何避免因为用户把所有的本地分支都推送到了共享版本库 ...