Read twice from a file

For my homework, I have to read the double values ​​from the file and sort them. These are some of the meanings. But when you read them with my code, when they print them out for testing, they are written in integer form.

std::ifstream infile (in_File);
double a;
while(infile>>a)
{
    std::cout<<a<<std::endl;
}

My doubles start with 185261.886524, then237358.956723

And my code will print 185262, then 237359and so on.

+4
source share
3 answers

Try adding this at the top of your main():

setlocale(LC_ALL, "C");

"C" . , "," ".". .

#include <clocale> .

: , , #include <iomanip> :

std::cout << std::setprecision(20);

setprecision .

+6

, : cout 6 double, 185262, 185261, . std::setprecision, .

+1

, , .. :

#include <locale>

and then use the method imbue:

std::ifstream infile (in_File);
infile.imbue(std::locale("C"));
double a;
while(infile>>a)
{
    std::cout<<a<<std::endl;
}
0
source

Source: https://habr.com/ru/post/1570238/


All Articles