The type long long appeared in the c99 standard. In 32-bit architectures, the size of this type is 64 bits. The standard introduces a format string for printf-like functions for this type:% lld (% llu for unsigned).
But as often happens, written simply by reference books does not always work. Faced with the need to recompile your code using MinGW / GCC (which would seem to ensure compatibility and portability of code between GNU / Linux and windows platforms), found that the behavior of this type was significantly different from that described: the number was output as 32-bit.
It turned out that MinGW uses calls to windows functions. But windows, as you know, cares about backward compatibility with old versions: when a new standard appeared, they did not adjust the functions to it, but continued to use a non-standard format string for this type:% I64d. Here is the
corresponding page in msdn describing this - no% lld.
')
But despite this, in Visual Studio 2005,% lld is processed normally, but in MinGW, which uses the windows functions, it does not.
In short, voodoo programming
Total:
It is good that if you use the standard C ++ classes instead of C functions, then such problems do not arise. The solution for outputting a number in the string as 0000001234 (10 characters, right alignment, filling empty positions with zeros) looks like this:
stringstream stream;
string str;
long long number = 1234LL;
stream.flags(ios::right);
stream.fill( '0' );
stream.width( 10 );
stream << number;
stream >> str;
Result: str == "0000001234";