C++常用类型转换
来源:互联网 发布:阿尔法淘宝宝贝下载器 编辑:程序博客网 时间:2024/06/05 21:56
1. int to string
1. int sprintf( char *buffer, const char *format [, argument] ... );
<stdio.h>
例如:
int ss;
char temp[64];
string str;
ss = 1000;
sprintf(temp, "%d", ss);
string s(temp);
//调用string的方法
cout<<s.c_str()<<endl;//1000
cout<<s.size()<<endl; //长度为4
2.char *_itoa( int value, char *string, int radix );
<stdlib.h>
例如:
char buffer[20];
int i = 3445;
_itoa( i, buffer, 10 );
string s(buffer);
3. stringstream( )
<sstream.h>
例如:
int hello=4;
stringstream ss;
ss<<hello;
string s=ss.str();
//调用string的方法
cout<<s.c_str()<<endl;
清空:
sst.str("");
clear()是为错误的控制状态设置新值。
2. string to int
1. atoi()
int i = atoi(str.c_str());
2. stringstream
stringstream ss;
string str = "123";
int val;
ss << str;
str >> val
3. boost::lexical_cast<int>()
int val = boost::lexical_cast<int>(string("123"));
- C语言的常用类型转换函数
- C语言常用数值类型转换函数
- <C/C++> 类型转换
- C/C++:类型转换
- 常用类型转换
- 常用的类型转换
- VC常用类型转换
- C++常用类型转换
- 常用类型转换简记
- 常用时间类型转换
- 常用类型的转换
- 类型转换常用方法
- 常用的类型转换
- Erlang常用类型转换
- 常用的类型转换
- python常用类型转换
- qt 常用类型转换
- C++常用类型转换
- 常用JDBC连接数据库方法
- MyEclipse 快捷键
- 转载我老婆写的当性别遇到就业
- JSP页面层的经验备忘总结
- Image To SQL Server
- C++常用类型转换
- 线段树入门 POJ 2182 Lots Cows
- ClipImage
- 倒霉的牧羊人
- Eclipse快捷键
- Hibernate(2)批量更新
- 一些计算机技术术语的缩写
- C# 资源文件的使用
- spring 事务并发 网上卖书的例子