0

My txt is full of floating point numbers, like this:

-6.279745101928710938e+00 -6.499424934387207031e+00 -6.950426101684570312e+00 -7.428587913513183594e+ ...

My code:

std::vector<std::vector<double>> voice(10, std::vector<double>(10));
ifstream fp("../target.txt");
if (!fp) {
    cout << "Error, file couldn't be open" << endl;
    return 1;
}
for(int i=0;i<10;i++)
{
    for(int j=0;j<10;j++)
    {
        if ( !fp )
        {
            std::cout << "read error" << std::endl;
            break;
        }
        fp >> voice[i][j];
    }
}
std::cout << "0 0:" << voice[0][0] << std::endl;
std::cout << "0 1:" << voice[0][1] << std::endl;

I get

0 0:-6.27975
0 1:-6.49942

The precision of floating point numbers is discarded, how can I get the full float from the txt?

Yongqi Z
  • 439
  • 5
  • 14
  • 2
    Does https://stackoverflow.com/questions/554063/how-do-i-print-a-double-value-with-full-precision-using-cout answer your question? – K.R.Park Mar 02 '22 at 02:03
  • 1
    I think the floating point values are properly parsed, but output is truncated according to default setting of `std::cout`. Check the question above. – K.R.Park Mar 02 '22 at 02:05

0 Answers0