STL中:有向std::string输出的方法吗?有从std::string到int的转换方法吗?
时间:2008-07-24 13:55:47
来源:论坛整理 作者: 编辑:chinaitzhe
有向std::string输出的方法吗?
取代sprintf
有从std::string到int的转换方法吗?
取代atoi
网友回复:stringstream/istringstream/ostringstream
网友回复:string设计就是用来高效率的构建,编辑,查找字符或字符串的
而不是用来进行这些转换的,把它做为容器类来操作并配合stl的算法可以实现上述操作
网友回复:
- C/C code
Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ using std::istringstream; istringstream stringReader; // 字符串读取器 // 从字符串中解析出数字 stringReader.str(integerPartString); // 使用字符串读取工具读取整数部分的字符串 long long integerPart = 0LL; stringReader>>integerPart; // 读出一个整数
这么实现的。谢谢二楼的。
网友回复:
网友回复:boost有一个专门用来转换的类lexical_cast
/*
*/
#include <boost/lexical_cast.hpp>
#include <string>
#include <iostream>
void main()
{
std::string str="2008";
int value=boost::lexical_cast <int>(str);
std::cout < <value;
}
关键字:STL,std,string,输出,方法,
下一篇:下面没有链接了











文章评论
共有 0 位网友发表了评论 此处只显示部分留言 点击查看完整评论页面