my program is pretty simple:
#include <iostream>
#include <stdio.h>
using namespace std;
int main()
{
long double a = 4.5;
printf("%Lg", a);
return 0;
}
When compiled, there is one warning:
warning: unknown conversion type character 'L' in format [-Wformat=]|
The output in the console is
-1.28823e-231
The documentation is pretty clear about printing long doubles, it simply states that the correct parameter for this format is L. What am I doing wrong? I'm using codeblocks, mingw32-g++ compiler under Windows 10.
P.S.: cout produces the same output.
You have a compiler problem:
Therefore, you need
double double
:Instead of
printf()
, usestd::cout
coupled withstd::scientific
, for example:It is best not to use both
stdio.h
andiostream
in the same project, as they can sometimes interfere with each other.PS. On the subject, also available are:
std::hex
,std::dec
(decimal),std::boolalpha
(true, false) and more.