• Advertisement
Sign in to follow this  

Errors

This topic is 4616 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

not sure why this is generating errors string s = "ab2c3d7R4E6"; string num ="0123456789"; vector<string> a; int pos = 0; int nt; while((nt = s.find_first_of(num,pos)) != string::npos){ a.push_back(s[nt]); //invalid conversion from `char' to `const char*' pos = nt+1; }

Share this post


Link to post
Share on other sites
Advertisement
Well, if you're reffering to the line about the invalid conversion, I'd suggest you take a s.substr().c_str(). That would procuce a const char string to be copied into the vector. I don't know if you could even fo s[nt].c_str(). Maybe that would work. Check this site out: http://www.cppreference.com/index.html

Share this post


Link to post
Share on other sites
the [] operator returns a reference to a char, not a reference to a string. You could use

a.push_back(string(1,s[nt]));

instead.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement