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

  • Home
  • SEARCH
  • 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 3322570
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T23:11:52+00:00 2026-05-17T23:11:52+00:00

Just curious about the encodings that system is using when handling string storing(if it

  • 0

Just curious about the encodings that system is using when handling string storing(if it cares) and printing.

Question 1: If I store one-byte string in std::string or two-byte string in std::wstring, will the underlying integer value differ depending on the encoding currently in use? (I remember that Bjarne says that encoding is the mapping between char and integer(s) so char should be stored as integer(s) in memory, and different encodings don’t necessarily have the same mapping)

Question 2: If positive, std::string and std::wstring must have the knowledge of the encoding themselves(although another guy told me this is NOT true)? Otherwise, how is it able to translate the char to correct integers and store them? How does the system know the encoding?

Question 3: What is the default encoding in one particular system, and how to change it(Is it so-called “locale”)? I guess the same mechanism matters?

Question 4: What if I print a string to the screen with std::cout, is it the same encoding?

  • 1 1 Answer
  • 3 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-05-17T23:11:52+00:00Added an answer on May 17, 2026 at 11:11 pm

    (I remember that Bjarne says that
    encoding is the mapping between char
    and integer(s) so char should be
    stored as integer(s) in memory)

    Not quite. Make sure you understand one important distinction.

    • A character is the minimum unit of text. A letter, digit, punctuation mark, symbol, space, etc.
    • A byte is the minimum unit of memory. On the overwhelming majority of computers, this is 8 bits.

    Encoding is converting a sequence of characters to a sequence of bytes. Decoding is converting a sequence of bytes to a sequence of characters.

    The confusing thing for C and C++ programmers is that char means byte, NOT character! The name char for the byte type is a legacy from the pre-Unicode days when everyone (except East Asians) used single-byte encodings. But nowadays, we have Unicode, and its encoding schemes which have up to 4 bytes per character.

    Question 1: If I store one-byte string
    in std::string or two-byte string in
    std::wstring, will the underlying
    integer value depend on the encoding
    currently in use?

    Yes, it will. Suppose you have std::string euro = "€"; Then:

    • With the windows-1252 encoding, the string will be encoded as the byte 0x80.
    • With the ISO-8859-15 encoding, the string will be encoded as the byte 0xA4.
    • With the UTF-8 encoding, the string will be encoded as the three bytes 0xE2, 0x82, 0xAC.

    Question 3: What is the default
    encoding in one particular system, and
    how to change it(Is it so-called
    “locale”)?

    Depends on the platform. On Unix, the encoding can be specified as part of the LANG environment variable.

    ~$ echo $LANG
    en_US.utf8
    

    Windows has a GetACP function to get the “ANSI” code page number.

    Question 4: What if I print a string
    to the screen with std::cout, is it
    the same encoding?

    Not necessarily. On Windows, the command line uses the “OEM” code page, which is usually different from the “ANSI” code page used elsewhere.

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

Sidebar

Related Questions

Just curious. I heard something about the new G1GC addressing that latency problem. I
i'm just curious. so i ask this particular question about SQLite. I haven't use
This is just an I am Curious question. In C#-in-depth Jon Skeet says about
I am just curious about the role that self plays within an object. I
i was just curious about webbot project and i wish that i could create
Quick question if I may: I am just curious about the following (see below)
I'm mostly just curious about this. Do assemblies that would be considered part of
I'm just curious about if letting installed some snippets that are not essentials to
It might be a silly question but I am just curious about what goes
I am just curious about the title. String a = abc\ndef; Console.Writeline(a); The output

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.