#include <bits/stdc++.h>
using namespace std;
int main() {
double d = 50;
printf ("%lf\n", d);
return 0;
}
If I compile it using g++ A.cpp -std=c++0x, output is 0.000000.
If I compile it using g++ A.cpp -std=gnu++0x, output is 50.000000 as desired.
Gives correct answer for using cout in both the cases.
What could be the possible issues? My g++ version is (tdm-1) 4.7.1
EDIT: Based on suggestion of andreyv, I checked using %f, it works correctly. But I dont know the reason for this :(
In C++98/C++03 the correct format to print a
double
is%f
. C++11 adopts a change from C99, where thel
length modifier was made no-op for thef
specifier, so that%lf
can also be used.EDIT: I read your first line as
-std=c++98
. Still the above facts are most likely related to the cause.Using %f works in both correctly. But I still can not find reason of %lf not working in c++0x.
Probably the C++11 support in the compiler/standard library is just incomplete. You could generate preprocessed sources in both cases and see whether two different
printf
versions are used.First one uses ___mingw_vprintf whereas the second one uses _printf. Hence it seems that error is due to this issue.