C++编程把科学计数法化为浮点数输出

#include <string>
#include <fstream>
using namespace std;

#define FIELD_COUNT 11

typedef struct _RECORD
{
string field[FIELD_COUNT];
friend ifstream& operator >> (ifstream& ifs, _RECORD& record)
{
for(size_t i = 0; i < FIELD_COUNT; i++)
{
ifs >> record.field[i];
}

return ifs;
}

friend ofstream& operator << (ofstream& ofs, _RECORD& record)
{
for(size_t i = 0; i < 7; i++)
{
ofs << record.field[i];
ofs << " ";
}
ofs <<record.field[9];

return ofs;
}
}RECORD;

int main ()
{
RECORD record;
ifstream ifs("F:\\7.1.txt");

if(ifs.fail())
{
return -1;
}

ofstream ofs("F:\\output.txt",ios::app);

while(ifs >> record)
{
if(!record.field[0].compare("A") && !record.field[1].compare("G1"))
{
ofs << record;
ofs << endl;
}
}
}
怎么把record.field[9],也就是第10列的数据化为浮点数输出到文件呢?

第1个回答  2014-09-17
float format
fixed: write floating point values in fixed-point notation.
scientific: write floating-point values in scientific notation.

写法就是:
float a = 0.0001f;
std::cout.setf(std::ios::fixed, std::ios::floatfield);
std::cout << a << std::endl;追问

能根据我的代码来写么,这个貌似不行

本回答被提问者和网友采纳
相似回答