现在的位置: 首页 > 综合 > 正文

数值换换为字符串(3)

2019年09月24日 ⁄ 综合 ⁄ 共 426字 ⁄ 字号 评论关闭

采用Boost库中的lexical_cat实现数值到字符串的转换

Boost库下载地址:www.boost.org


#pragma warning(disable:4996)
#include <iostream>
#include <cstdlib>
#include <string>
using namespace std;
 
#include <boost/lexical_cast.hpp>
using namespace boost;
 
int main(int argc, char **argv)
{
 
	//定义需要需要转换的数值
	int i =10;
	//定义字符串变量
	std::string str;
	
	//采用boost库中的lexical_cast函数可以实现任意类型数值到字符串的转换
	str = boost::lexical_cast<std::string>(i);
	
	std::cout<<str<<std::endl;		
	
	return EXIT_SUCCESS;
}

抱歉!评论已关闭.