Help with C++ and strings

Started by
1 comment, last by MilesRobson 11 years, 11 months ago
I'm currently in an Intro C++ class, and I'm learning about Strings and Member Functions of them.
I have questions that are like this:

Assume that name is a variable of type string that has been assigned a value. Write an expression whose value is a string containing the first character of the value of name . So if the value of name were "Smith" the expression's value would be "S".

or

Assume that name is a variable of type string that has been assigned a value. Write an expression whose value is a string containing the last character of the value of name . So if the value of name were "Smith" the expression's value would be "h".

or

Assume that word is a variable of type string that has been assigned a value. Write an expression whose value is a string consisting of the last three characters of the value of word . So if the value of word were "biggest" the expression's value would be "est".

I know things like name[0] and name[name.length() - 1], but I don't know how to turn those into a string in one expression. I've been looking for a table or list of member functions that can help me do this, but I'm stuck. Any directions or aid would be great. :D

(Apologies if this should go into general programming)

Twitter

Learning to code in general, Junior at FAU

Advertisement
Use std::string::substr.

Beginners is fine.
I turned the page in my book on accident.

The table was continued on the other side. /facepalm

Thanks, alvaro. :D

Twitter

Learning to code in general, Junior at FAU

This topic is closed to new replies.

Advertisement