Jump to content

View more

Image of the Day

The night is still, but the invasion brings chaos. #screenshotsaturday #hanako #indiegame #gameart #ue4 #samurai https://t.co/cgILXuokoS
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

Help with C++ and strings

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
2 replies to this topic

#1 Confirm4Crit   Members   

310
Like
0Likes
Like

Posted 18 May 2012 - 04:28 PM

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


#2 Álvaro   Members   

20927
Like
3Likes
Like

Posted 18 May 2012 - 04:33 PM

Use std::string::substr.

Beginners is fine.

#3 Confirm4Crit   Members   

310
Like
0Likes
Like

Posted 18 May 2012 - 05:06 PM

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





Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.