一、int float 转成string输出
参考:https://www.cnblogs.com/lyggqm/p/4562727.html
#include "stdafx.h"
#include <iostream>
#include <string>
#include <sstream> //引入stringstream头文件
using namespace std;
int main()
{
stringstream strStream;
int a = 100;
float f = 23.5566;
//int、float类型都可以塞到stringstream中
strStream << a << "----" << f;
string s = strStream.str();
cout << s << endl;
system("pause");
return 0;
}
输出结果:
二、 float 转成CString输出
#include <afx.h>
#include "stdafx.h"
#include <iostream>
#include <string>
//#include <cstringt.h>
#include "atlstr.h"
using namespace std;
int main()
{
//stringstream strStream;
//int a = 100;
//float f = 23.5566;
int、float类型都可以塞到stringstream中
//strStream << a << "----" << f;
//string s = strStream.str();
CString str = "1";
float num = 1.46;
//str="1.46"
str.Format(_T("%f"), num);
cout << str << endl;
system("pause");
return 0;
}
#include <afx.h>
#include "stdafx.h"
#include <iostream>
#include <string>
//#include <cstringt.h>
#include "atlstr.h"
using namespace std;
int main()
{
CString str = "";
float num = 1.46;
str.Format(_T("%f"), num);
printf("%s", str);
//cout << str << endl; //CString是MFC的类,不能用cout输出。
//system("pause");
return 0;
}