Use atol to convert string to long value - C++ Data Type

C++ examples for Data Type:int

Description

Use atol to convert string to long value

Demo Code

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

int main() /*www.  j  av  a2s  .c om*/
{ 
    long x = atol( "1000000" ); // convert string to long 

    cout << "The string \"1000000\" converted to long is " << x 
        << "\nThe converted value divided by 2 is " << x / 2 << endl; 
}

Result


Related Tutorials