The sprintf is not displaying the string message appropriately. The message to be displayed is
Value out of range. Range is -2147483648 and 2147483647. However it is printed as
Value out of range. Range is -2147483648 and 0.
#include <iostream>
#include <string>
int main()
{
__int64 tmpminVal = -2147483648;
__int64 tmpmaxVal = 2147483647;
std::string strTemp = "Value out of range. Range is %d and %i ";
char buffer[100];
int n = sprintf (buffer, strTemp.c_str(), tmpminVal,tmpmaxVal);
strTemp = buffer;
std::cout << strTemp << std::endl;
return 0;
}
Please provide the reason why it is does so.
%dand%iare forintbut you provide__int64. This causes undefined behaviour. You will need to find out what your platform's specifier is for__int64. (If you uselong longinstead then%lldis the specifier).%dand%iexpect anint, not an__int64. What you see is probably the effect oftmpminValbeing split into two chunks of 32 bits each.__int64is%I64d.