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 8470993
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T16:40:23+00:00 2026-06-10T16:40:23+00:00

I need to implement this Java code in (unmanaged) c++: byte[] b = string.getBytes(UTF8);

  • 0

I need to implement this Java code in (unmanaged) c++:

byte[] b = string.getBytes("UTF8");

I’m new to c++, and can’t find anything to do this. It has to be platform independent, if possible. Using c++11 compiler.

  • 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-10T16:40:25+00:00Added an answer on June 10, 2026 at 4:40 pm

    Java String is roughly equivalent to std::u16string, a specialization of std::basic_string. I suggest you try something like…

    std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> convert;
    std::string converted = convert.to_bytes(u"HELLO, WORLD!");
    const char *bytes = converted.data();
    

    Note this relies on C++11; it might be sometime before your compiler vendor fully supports these features.

    Here, we utilize the newly introduced std::wstring_convert to convert from a wide-character UTF-16 string to the UTF-8 multibyte string via to_bytes (it also supports conversion in the other direction, too).

    This is made possible via the (also newly introduced) std::codecvt_utf8_utf16 conversion facet. It takes care of the actual conversion for us nicely.

    Besides that, it makes use of the new character literal prefixes added with C++11 — in particular, u, which is for char16_t UTF-16 strings 🙂 There are also u8 and U for UTF-8 and UTF-32, respectively.


    PS data is (as of C++11) guaranteed to be equal to c_str and therefore can be relied upon to be NUL-terminated.

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

Sidebar

Related Questions

This is a question about how to implement the equals method when I need
So, I need some way to implement an undirected network ( I think this
I need to implement portable code, but I do not know how to deal
I need to implement some new functions on an editor. I picked Emacs -
I need to implement an ArrayList which can hold like person records. I can
I'm new to Ruby (being a Java dev) and trying to implement a method
I want to implement Java code to send and receive sms through serial comport
I need to implement the same functionality as this function on Win7 x64. I
I need to create a class with exactly the same methods as java.lang.String .
I was hoping to implement a simple XMPP server in Java. What I need

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.