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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T13:50:53+00:00 2026-06-04T13:50:53+00:00

A program in C++ needs to read a file that is encoded in utf-8.

  • 0

A program in C++ needs to read a file that is encoded in utf-8. Unfortunately, using char* it cannot get extended characters (☺☻♥♦•◘ and so on), and wchar_t* interprets them wrongly. My algorithm to manage it is:

1) Make a new file

2) Name it to [original name]Utf-16

3) Copy original file to new, making a conversion simultaneously

4) Extract data.

5) Delete this temporary file when it’s no longer needed.

I’m stuck at 3), is there somewhere a function like “FileUTF8toUTF16”?

  • 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-04T13:50:54+00:00Added an answer on June 4, 2026 at 1:50 pm

    This is what I use

    int nLenWide = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)(pData + nOffset), 
            (int)(nDataLen - nOffset), NULL, 0);
    if (MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)(pData + nOffset), 
            (int)(nDataLen - nOffset), 
            str.GetBuffer(nLenWide), nLenWide) != nLenWide)
    {
        str.ReleaseBuffer(0);
        ASSERT(false);
        return str;
    }
    str.ReleaseBuffer(nLenWide);
    return str;
    

    In which pData is a BYTE pointer to the actual utf-8 data, nOffset is usually 3 (the BOM).

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

Sidebar

Related Questions

I have a file I'm using to hold system information that my program needs
I am writing a program that needs to read a set of records that
I'm currently writing a program that needs to compare each file in an ArrayList
I'm working on a compression program which needs to read a file into RAM
I am writing an MPI program that needs to read a part of a
My program needs to read chunks from a huge binary file with random access.
The program that I am writing needs to do this: read every line of
Let's say I have a simple config file that my c program needs to
i got a program that needs to check if a chunk of a file
I'm writing a program that needs to read and write lots of data in

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.