How to convert a string iterator to a char*

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • AndreasL

    How to convert a string iterator to a char*

    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:

    Code:
    MyFunction(string &s)
    {
        string::iterator it = s.begin();
        // Sometimes the string is iterated a few characters here
        DWORD value = strtoul(it, NULL, 16);
        // Post processing data
    }
    When I try to execute this code I get this error message.

    error: cannot convert '__gnu_cxx::__n ormal_iterator< char*, std::basic_stri ng<char, std::char_trait s<char>, std::allocator< char> > >' to 'const char*' for argument '1' to 'long unsigned int strtoul(const char*, char**, int)'|
  • Oralloy
    Recognized Expert Contributor
    • Jun 2010
    • 988

    #2
    try
    Code:
    MyFunction(string &s) 
    { 
        string::iterator it = s.begin(); 
        // Sometimes the string is iterated a few characters here 
        DWORD value = strtoul(s.c_str(), NULL, 16); 
        // Post processing data 
    }

    Comment

    • Oralloy
      Recognized Expert Contributor
      • Jun 2010
      • 988

      #3
      Just as an aside, why aren't you wrapping a stream around the string and just extracting values that way?

      Comment

      Working...