String question

closed account (jwkNwA7f)
How can I get the first or second letter of a string?

Also how can I add letters to a string?


Thanks for your help!
the string obj has lots of functions. I know off hand that you can use obj.substr(a,b) which will return a letter. There's also a function to concatenate.

That's more complicated. Just use string[0] or string[1] to get the first and second letters. To add letters to the end, use a function.
std::string s( "ABCDEF" );

for ( std::string::size_type i = 0; i < s.size(); i++ ) std::cout << s[i];
std::cout << std::andl;

s += 'G';

std::cout << s << std::endl;
Topic archived. No new replies allowed.