关于转换的问题,平时用到一些 内置类型之间的 转换方法如atoi atof itoa sprintf 等 istrstream ostrstream strstream【2013.10.21】
来源:互联网 发布:网络银行交易额 编辑:程序博客网 时间:2024/06/10 18:20
欢迎加入我们的QQ群,无论你是否工作,学生,只要有c / vc / c++ 编程经验,就来吧!158427611
1. 关于转换的问题,平时用到一些 内置类型之间的 转换方法如atoi atof itoa sprintf 等可以转换成字符串的方法 这都是c下面的方法,c++下面有
istrstream ostrstream strstream //这几个是处理C风格的字符串 即字符串
istringstream ostringstream stringstream //这几个是处理C++ 即string 类
主要处理代码可以如下:
我们要格式化一个 ”今天是 10 号“
char str[100] = {0};
int day = 10;
sprintf(str,"今天是 %d 号",day); //sprintf 方法
char *pstr = new char[100];
ostrstream ostr(pstr,100);
ostrstream << "今天是 " << 10 << " 号" << ends; //结尾要ends \0效果 不然会有溢出的危险
cout << pstr <<endl; // "今天是 10 号"
ostringstream ostring;
ostring << “今天是 ” << 10 << " 号" <<endl;
string str = ostring,str();//获取字符串
或者:
ostring >> str; //同样效果
这些是转成字符串。。下面是字符串转 int float 等...
atoi atof 就不写代码了。
istrstream istr("10");
int iout ;
istr >> iout; //iout = 10 了
cout << iout <<endl;//输出 10
简单吧。。。
istringstream istring("10");
int iout;
istring >> iout; //同样iout=10了
cout <<iout <<endl; //输出10
setprecision (显示几位小数)
precision ( 显示几位数字 )
很简单吧。。。呵呵。。。。还有更多用法哦...方便!
而且一个stream对象都可以进行多次转换,只要在转换前调用clear() 方法清理一下就ok啦!
欢迎加入我们的QQ群,无论你是否工作,学生,只要有c / vc / c++ 编程经验,就来吧!158427611
- 关于转换的问题,平时用到一些 内置类型之间的 转换方法如atoi atof itoa sprintf 等 istrstream ostrstream strstream【2013.10.21】
- atof(),atoi(),itoa(),sprintf()等用法总结,强大的sprintf()
- atof(),atoi(),itoa(),sprintf()等用法总结
- C++ 类型转换 atoi atol atof itoa ftoa <stdlib.h>
- _itoa atoi、atof、itoa、itow _itoa_s 类型转换使用说明
- _itoa atoi、atof、itoa、itow _itoa_s 类型转换使用说明
- _itoa atoi、atof、itoa、itow _itoa_s 类型转换使用说明
- _itoa atoi、atof、itoa、itow _itoa_s 类型转换使用说明
- _itoa atoi、atof、itoa、itow _itoa_s 类型转换使用说明
- _itoa atoi、atof、itoa、itow _itoa_s 类型转换使用说明
- _itoa atoi、atof、itoa、itow _itoa_s 类型转换使用说明
- _itoa atoi、atof、itoa、itow _itoa_s 类型转换使用说明
- _itoa atoi、atof、itoa、itow _itoa_s 类型转换使用说明
- _itoa atoi、atof、itoa、itow _itoa_s 类型转换使用说明
- atoi,itoa,sprintf等函数的实现
- 常用的函数:atoi,itoa,atof,_ttoi等
- 常用的函数:atoi,itoa,atof,_ttoi等
- 常用的函数:atoi,itoa,atof,_ttoi等
- proc源码解析(一)--proc文件系统的内容
- 使用JAXP进行DOM解析( DocumentBuilderFactory、DocumentBuilder、Document)
- VC++中使用内存映射文件处理大文件(转)
- SVG + Javascript 实现的五边形的扫雷游戏
- 软件开发启示录——迟到的领悟
- 关于转换的问题,平时用到一些 内置类型之间的 转换方法如atoi atof itoa sprintf 等 istrstream ostrstream strstream【2013.10.21】
- proc源码解析(二)--proc数据结构
- [数据结构]程杰模式串匹配、KMP算法及其改进(代码)
- proc源码解析(三)--proc初始化
- proc源码解析(五)--proc的管理函数
- UVa 10794 The Deadly Olympic Returns!!!
- proc源码解析(六)--proc文件读写函数
- 新站优化的几点技巧
- proc源码解析(七)--查找目录项