Skip to main content
gamedev.net
🔒 Locked

Errors

Started by Gink 1 reply 700+ views
Original Post
Gink
Gink
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; }
moucard
moucard
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
Dave Hunt
Dave Hunt
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.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.