Using strtoul to converts to char based string an unsigned long integer. - C++ Data Type

C++ examples for Data Type:char array

Description

Using strtoul to converts to char based string an unsigned long integer.

Demo Code

#include <iostream> 
#include <cstdlib> // strtoul prototype 
using namespace std; 

 int main() //from  w w w  .  j  av a  2  s  .  c o  m
 { 
    unsigned long x; 
    const char *string1 = "1234567abc"; 
    char *remainderPtr; 

    // convert a sequence of characters to unsigned long 
    x = strtoul( string1, &remainderPtr, 0 ); 

    cout << "The original string is \"" << string1 
        << "\"\nThe converted value is " << x 
        << "\nThe remainder of the original string is \"" << remainderPtr 
        << "\"\nThe converted value minus 567 is " << x - 567 << endl; 
    return 0;
 }

Result


Related Tutorials