Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7807427
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T02:51:08+00:00 2026-06-02T02:51:08+00:00

What are the rules for the escape character \ in string literals? Is there

  • 0

What are the rules for the escape character \ in string literals? Is there a list of all the characters that are escaped?

In particular, when I use \ in a string literal in gedit, and follow it by any three numbers, it colors them differently.

I was trying to create a std::string constructed from a literal with the character 0 followed by the null character (\0), followed by the character 0. However, the syntax highlighting alerted me that maybe this would create something like the character 0 followed by the null character (\00, aka \0), which is to say, only two characters.

For the solution to just this one problem, is this the best way to do it:

std::string ("0\0" "0", 3)  // String concatenation 

And is there some reference for what the escape character does in string literals in general? What is ‘\a’, for instance?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T02:51:10+00:00Added an answer on June 2, 2026 at 2:51 am

    Control characters:

    (Hex codes assume an ASCII-compatible character encoding.)

    • \a = \x07 = alert (bell)
    • \b = \x08 = backspace
    • \t = \x09 = horizonal tab
    • \n = \x0A = newline (or line feed)
    • \v = \x0B = vertical tab
    • \f = \x0C = form feed
    • \r = \x0D = carriage return
    • \e = \x1B = escape (non-standard GCC extension)

    Punctuation characters:

    • \" = quotation mark (backslash not required for '"')
    • \' = apostrophe (backslash not required for "'")
    • \? = question mark (used to avoid trigraphs)
    • \\ = backslash

    Numeric character references:

    • \ + up to 3 octal digits
    • \x + any number of hex digits
    • \u + 4 hex digits (Unicode BMP, new in C++11)
    • \U + 8 hex digits (Unicode astral planes, new in C++11)

    \0 = \00 = \000 = octal ecape for null character

    If you do want an actual digit character after a \0, then yes, I recommend string concatenation. Note that the whitespace between the parts of the literal is optional, so you can write "\0""0".

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Are there rules of thumb that help determine which to use in what case?
Are there are any rules for when to use Client-Side validation and when to
Are there overall rules/guidelines for what makes a method thread-safe? I understand that there
I have to escape two special characters and , in the string with the
With at-rules, it's possible to have a ruleset for elements during that at-rule event
I'm a little surprised that there isn't some information on this on the web,
Does any one have a handy ready to use method to escape wildcards, invalid
Is there a list of Regex implementations on the web, showing their differences /
I have a list of colors, with textures that I want to show to
What rules or tips should I follow to enable a function to use NRV

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.