devxlogo

How to Print an __int64 Number in VC++

How to Print an __int64 Number in VC++

You can use the printf() function as in the following example:

 #include using namespace std;int main(){  __int64 i64 = 4294967296;  printf("%I64d
", i64); //in decimal  printf("%I64x
", i64); //in hexa  return 0;}

You can also use the function Int64ToString(). The next example transforms an __int64 into a string in a specified radix:

 #include #include #include string Int64ToString(__int64 const& ri64, int iRadix=10){  bool bNeg = (ri64 < 0);  __int64 i64 = ri64;  string ostrRes;  bool bSpecial = false;  if(true == bNeg)  {    i64 = -i64;    if(i64 < 0)      //Special case number -9223372036854775808 or _0x8000000000000000      bSpecial = true;    ostrRes.append(1, '-');  }  int iR;  do  {    iR = i64 % iRadix;    if(true == bSpecial)      iR = -iR;    if(iR < 10)      ostrRes.append(1, '0' + iR);    else      ostrRes.append(1, 'A' + iR - 10);    i64 /= iRadix;  }  while(i64 != 0);  //Reverse the string  string::iterator it = ostrRes.begin();  if(bNeg)    it++;  reverse(it, ostrRes.end());  return ostrRes;}int main(){  __int64 i64 = 4294967296;  cout << Int64ToString(i64) << endl; //in decimal  cout << Int64ToString(i64, 16) << endl; //in hexa  return 0;}
See also  Why ChatGPT Is So Important Today
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist