马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 new_guard 于 2017-7-7 11:23 编辑 #include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include "atlstr.h"
#include <cstdio>
using namespace std;
void main()
{
float mag[6] = {-0.14189115,0.039332587,-0.044832617,0.83130932,0.0039432552,0.028655458};
ofstream out;
string temp_t;
char buffer[15];
out.open("first.txt");
if(!out.is_open())
{
cerr << "打开out文件出错!\n";
return;
}
for(int i = 0; i < 6; i++)
{
sprintf_s(buffer, "%0.*f", 10, mag[i]); //此处代码重要
temp_t = buffer;
cout << temp_t << "\t"; //见下图显示结果
out << temp_t <<" ";
temp_t = "";
}
out.close();
return;
}
原本想保留指定位数的小数,不足位数补零,但遇到奇葩问题是乱补数,我就凌乱了......................
|