// changstring.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <iostream>
#include <sstream>
#include <string>
#include <cstdlib>
using namespace std;
template <class T>
void convertFromString(T &, const std::string &);
template <class T>
std::string ConvertToString(T);
int _tmain(int argc, _TCHAR* argv[])
{
std::string s("123");
// Convert std::string to int
int i = 0;
convertFromString(i,s);
std::cout << i << std::endl;
float f=12.5;
string str=ConvertToString(f);
cout<<str<<endl;
cin>>i;
}
template <class T>
void convertFromString(T &value, const std::string &s)
{
std::stringstream ss(s);
ss >> value;
}
template <class T>
std::string ConvertToString(T value)
{
std::stringstream ss;
ss<<value;
return ss.str();
}
:string转int,double? (C/C++)
最新推荐文章于 2023-06-03 16:07:18 发布