Блог пользователя PraveenDhinwa

Автор PraveenDhinwa, 12 лет назад, По-английски
#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 :(

  • Проголосовать: нравится
  • +12
  • Проголосовать: не нравится

»
12 лет назад, скрыть # |
Rev. 2  
Проголосовать: нравится +6 Проголосовать: не нравится

In C++98/C++03 the correct format to print a double is %f. C++11 adopts a change from C99, where the l length modifier was made no-op for the f 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.