Jump to content
  • Advertisement
Sign in to follow this  
homeboye

[C/C++] insert a char into a string?

This topic is 4439 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hello, i'm trying to insert the char " to a string, but no luck :i've tried with the typecast char, also tried itoa and strcat(string,""") :/ i figure i need help right about now. ty.

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by Simian Man
Use \"

(This is called an escape character)

(Assuming C++) When specifying a single character, you could alternatively use '"'.

For example,

std::string pString;

pString += '"'; //'\x22' can also be used.




Share this post


Link to post
Share on other sites
Quote:
Original post by Simian Man
Use \"

(This is called an escape character)
To expand on this a little:
const char* szString = "My name is \"Admiral Cheeselover\"."

Other escaped characters:
\n = Newline
\r = Carrige return
\b = Backspace
\0 = ASCII zero, I.e. NULL terminator
There's a bunch more, but those are the most common ones.

Share this post


Link to post
Share on other sites
Quote:
Original post by Evil Steve
There's a bunch more, but those are the most common ones.

I'd just like to add that '\\', and '\t' are pretty common as well.

- '\\' being a backslash.
- '\t' being a horizontal tab.

Share this post


Link to post
Share on other sites
Quote:
Original post by raz0r
Quote:
Original post by Evil Steve
There's a bunch more, but those are the most common ones.

I'd just like to add that '\\', and '\t' are pretty common as well.

- '\\' being a backslash.
- '\t' being a horizontal tab.


Just as: -

- '\''
- '\"'

also are

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!