1. 程式人生 > >C++字串數值的轉換(to_string/stoi/stod)

C++字串數值的轉換(to_string/stoi/stod)

#include<iostream>
#include<string>

using namespace std;

int main()
{
	string s1 = "2018.11";
	int a1 = stoi(s1);
	double c = stod(s1);
	float d = stof(s1);
	int a2 = a1 + 1;
	string b = to_string(a1);
	b.append(" is a string");
	
	cout << a1 <<"/"<<c<<"/"<<d<<"/"<<a2<<"/"<<b<< endl;
}