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






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

#include <cstdlib> // strtoul prototype
using std::strtoul;

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

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

   cout << x << "  "<< x - 567 << endl;
   return 0;
}
1234567  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