KrK's blog

By KrK, 8 years ago, In English,

Having used cin/cout streams all the time, I decided to learn scanf. Now I have some problems with reading long double. I use Dev-cpp.

There is a part of my program:
...
typedef long double ld;
...
pair <ld, ld> c[Maxn];
...
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%Lf %Lf", &c[i].first, &c[i].second);
cout << c[0].first << " " << c[0].second << endl;
...

My input:
3
-5 9
0 1
5 -1

Output:
0 0

So no long doubles are read. I tried to replace "Lf" with "Le", "LE", "Lg", "LG", "e", "E", "f", "g", "G", "le", "lE", "lf", "lg", "lG". None of them seems to be working. Where is the problem?

 
 
 
 
  • Vote: I like it
  • +5
  • Vote: I do not like it

»
8 years ago, # |
Rev. 4   Vote: I like it 0 Vote: I do not like it
It's better to read/output data in double (not long double), e.g.:

        long double r = 1.234567890123456;
        printf("%.10lf", double(r));

There is a same topic: http://codeforces.com/blog/entry/2071
»
8 years ago, # |
  Vote: I like it -21 Vote: I do not like it
%f - float
%lf - double
%llf - long double
»
8 years ago, # |
  Vote: I like it +10 Vote: I do not like it
Haven't used dev-cpp for a long time. It uses mingw - the crippled port of gcc for windows OS. Read here more about this particular problem.
»
8 years ago, # |
  Vote: I like it +9 Vote: I do not like it
A workaround is to read into a double variable and then cast it to long double.
Usually it is sufficient to read input as doubles.
The same goes for output.
»
8 years ago, # |
  Vote: I like it -17 Vote: I do not like it
Its not '%Lf' ,its '%lf'..