-
single-string to char
I see a lot of functions are meant for char's and not strings. FOr example, isalpha().
In my case I want to use isalpha but I have a string. The good news is it's a single digit string using substr to grab each individually.
I want to cast my (val.substr(1,1) into a char for isalpha to process. Everythign I read says string to char is a no-no.
Ideas?
-
Why are you using substr to grab 1 character? Why not operator[]? And why don't you just pass that value to std::isalpha?
-
operator? signs and symbols? Got a good link?
-
What? operator[] is the [] operator. as in std::string rtfm("foo"); rtfm[2]; evaluates to an object of type 'char' having a value of the second index in the rtfm object.
-
i thought that you meant [] but I didn't know if there was something I was missing...I didn't realize I could use it to pull individual characters from a string. Very nice. thanks.
-
That's what it's there for.
-
The SGI and Dinkumware sites have good documentation on standard library classes like string, and your favorite book should as well.
There are no isalpha type methods for strings because it is usually pretty easy to combine a character based method like isalpha with a string using an algorithm or a simple loop.