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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:20:47+00:00 2026-05-25T17:20:47+00:00

What would be the algorithm/implementation of the C++ code C++functionX in the following flow

  • 0

What would be the algorithm/implementation of the C++ code C++functionX in the following flow chart:

(JavaString) --getBytes--> (bytes) --C++functionX--> (C++String)

JavaString contents should match C++String contents as far as possible (preferably 100% for all possible values of JavaString)

[EDIT] The endianness of bytes can be ignored as there are ways to handle that.

  • 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-05-25T17:20:48+00:00Added an answer on May 25, 2026 at 5:20 pm

    Java:

    String original = new String("BANANAS");
    byte[] utf8Bytes = original.getBytes("UTF8");
    //save the length as a 32 bit integer, then utf8 Bytes to a file
    

    C++:

    int32_t tlength;
    std::string utf8Bytes;
    //load the tlength as a 32 bit integer, then the utf8 bytes from the file
    //well, that's easy for UTF8
    
    //to turn that into a utf-18 string in windows
    int wlength = MultiByteToWideChar(CP_UTF8, 0, utf8Bytes.c_str(), utf8Bytes.size(), nullptr, 0);
    std::wstring result(wlength, '\0');
    MultiByteToWideChar(CP_UTF8, 0, utf8Bytes.c_str(), utf8Bytes.size(), &result[0], wlength);
    //so that's not hard either
    

    To do this in linux, one uses the iconv library, which is incredibly powerful, but more difficult to use. Here’s a function that converts a std::string in UTF8 to a std::wstring in UTF32: http://coliru.stacked-crooked.com/view?id=986a4a07e391213559d4e65acaf231d5-e54ee7a04e4b807da0930236d4cc94dc

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

Sidebar

Related Questions

What would be the best hashing algorithm if we had the following priorities (in
I have just written some code for approximate string matching. I would like to
I am writing a basic genetic algorithm(string evolver) implementation in C . It takes
I'm not looking for an implementation, just pseudo-code, or at least an algorithm to
Which algorithm would you use to search short substrings in short texts? By short
What algorithm would you make a computer use, if you want to solve a
What algorithm would you suggest to identify how much from 0 to 1 (float)
On SO 18 Joel mentioned an algorithm that would rank items based on their
A friend was in need of an algorithm that would let him loop through
What would be the best algorithm for finding a number that occurs only once

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.