Using strtoul: convert string to unsigned long : Long « Data Type « C++






Using strtoul: convert string to unsigned long

  
#include <iostream>
#include <stdlib.h>
using namespace std;
int main()
{
   unsigned long x;
   char *string = "1234567abc", *remainderPtr;

   x = strtoul( string, &remainderPtr, 0 );
   cout << "The original string is \"" << string
        << "\"\nThe converted value is " << x
        << "\nThe remainder of the original string is \""
        << remainderPtr
        << "\"\nThe converted value minus 567 is " 
        << x - 567 << endl;
   return 0;
}
  
    
  








Related examples in the same category

1.cout for long intcout for long int
2.Using atol: convert string to long
3.Using strtol: convert string to long