Using strtol : convert from string « Data Types « C++ Tutorial






#include <iostream>
using std::cout;
using std::endl;

#include <cstdlib>
using std::strtol;

int main()
{
   long x;
   const char *string1 = "-1234567abc";
   char *remainderPtr;

   x = strtol( string1, &remainderPtr, 0 );

   cout << x << " " << remainderPtr << " " << x + 567 << endl;
   return 0;
}
-1234567 abc -1234000








2.29.convert from string
2.29.1.Using atof.
2.29.2.Using atoi
2.29.3.Using atol
2.29.4.Using strtod
2.29.5.Using strtol
2.29.6.Using strtoul