Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Home » Tip Bank » C++
Language: C++
Expertise: Intermediate
Apr 30, 2001

Converting a hex String to int


In a previous tip, I showed how to convert a string containing a hexadecimal to int using the sscanf() function. stringstream objects can perform this feat too, in a more object-oriented fashion. In the following program, a string containing a hexadecimal value is converted to int by using an istringstream object. First, the programmer instantiates an istringstream object and initializes it with the hexadecimal string. Then, the stringstream's setf() member function is called with the ios::hex flag. Finally, the istringstream object writes a decimal value that is equivalent to the hexadecimal value of the original string into the integer n:
 
#include <sstream>
#include <string>
using namespace std;
int main()
{
 string mem_addr = 
Danny Kalev
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date