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