By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,996 Members | 882 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,996 IT Pros & Developers. It's quick & easy.

How to convert a string iterator to a char*

P: n/a
Hi!

I have a string passed to a methos via a string&. I would like to convert this to an unsigned long.

How do I convert the string iterator to a char*?

with all the error checking code removed, it's basically this:

Expand|Select|Wrap|Line Numbers
  1. MyFunction(string &s)
  2. {
  3.     string::iterator it = s.begin();
  4.     // Sometimes the string is iterated a few characters here
  5.     DWORD value = strtoul(it, NULL, 16);
  6.     // Post processing data
  7. }
  8.  
When I try to execute this code I get this error message.

error: cannot convert '__gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >' to 'const char*' for argument '1' to 'long unsigned int strtoul(const char*, char**, int)'|
Oct 4 '10 #1
Share this Question
Share on Google+
2 Replies


Oralloy
Expert 100+
P: 983
try
Expand|Select|Wrap|Line Numbers
  1. MyFunction(string &s) 
  2.     string::iterator it = s.begin(); 
  3.     // Sometimes the string is iterated a few characters here 
  4.     DWORD value = strtoul(s.c_str(), NULL, 16); 
  5.     // Post processing data 
Oct 4 '10 #2

Oralloy
Expert 100+
P: 983
Just as an aside, why aren't you wrapping a stream around the string and just extracting values that way?
Oct 4 '10 #3

Post your reply

Sign in to post your reply or Sign up for a free account.