2

I have a file.txt with hundreds of numbers. They have many digits (max 20) after the point and I need to get them all without truncation, otherwise they introduce errors in the following computations. I made these numbers with matlab so it has a monstrous precision but now I must replicate this behaviour in my program.

I've done this way:

 fstream in;
 in.open(file.txt, ios::in);
 long double number;
 in>>number;

I also tried this

 in.precision(20);
 in>>number;

before each ">>" operation but it is vain.

If I copy and paste these numbers in my code assigning them to long double variables all goes well as it were matlab. It's a problem of functions or fstream, not precision of long double type, isn't it?

For examples, take this number 2.7239385667867091 and save it in a file.txt. Can you read all its digits with C++ and fstream?

user3290180
  • 4,260
  • 9
  • 42
  • 77
  • Why do you post a duplication of a question you just asked? If you want to add something, edit your original question. – T.C. Jun 25 '14 at 20:04
  • no one is answering and I need a help – user3290180 Jun 25 '14 at 20:12
  • If you exceed [max_digits10](https://en.cppreference.com/w/cpp/types/numeric_limits/max_digits10) then the trailing digits will be suspect. – Eljay May 15 '20 at 22:44

0 Answers0