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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T12:36:11+00:00 2026-05-20T12:36:11+00:00

I would like to ask for help … I am starting in C++ and

  • 0

I would like to ask for help … I am starting in C++ and I got this homework at school … We got to write function bool UTF8toUTF16 (const char * src, const char * dst ); which is supposed to read src file coded in UTF-8 and write it into dst file but in UTF-16. We also mustn’t use any other libraries than in my code down…

So the first thing I am trying to do is that I make a file “xx.txt” and in classic Windows notepad I write there for example char ‘š’. Then am trying to write a program which reads each char of this file in binary mode byte by byte (or bytes by bytes) and prints it’s value… but my program doesn’t work like that…

So I have this file ‘xx.txt’ where is only ‘š’ which has UTF-8 value ‘c5 a1’, UTF-16 value ‘0161’ and Unicode value ‘161’ and I suppose result that it will print: i = 161 (hex) or something close to this result at least…

Here is my code so far:

#include <stdio.h>
#include <stdlib.h>
#include <iomanip>
#include <iostream>
#include <fstream>

using namespace std;

int main ( void ) {
    char name[] = "xx.txt";
    fstream F ( name, ios::in | ios::binary );
    unsigned int i;
    while( F.read ((char *) & i, 2))
    /* I dont know what size to write there - I would guess it s '2' - because I need 2     bytes for the char with hexUTF-16 code '0161', but 2 doesnt work*/
    cout << "i = " << hex << i << " (hex) ";
    cout << endl;
    F.close();
    system("PAUSE");
    return 0;}

Thanks in advance

Nikolas Jíša

  • 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-20T12:36:12+00:00Added an answer on May 20, 2026 at 12:36 pm

    You don’t know how big a character is in utf8 until you finish parsing it, you need to read “chars” one at a time until you have a complete utf8 character.

    edit – you don’t say what you are getting as an output – but I suspect it’s a byte ordering issue.
    You might be better reading the input (if you know it is always a 16bit value) into a char array and then looking at the individual bytes.

    See http://www.joelonsoftware.com/articles/Unicode.html

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

Sidebar

Related Questions

I would like to ask for help. I got this homework to create a
I would like to ask some help. This is not homework but it is
I would like to ask for help with this, I wanted to check for
Hello everybody :D I would like to ask for your help on this problem.
i would like to ask for your help since I'm having difficulty resolving this
I would like to ask for help on how to achieve this. I have
I would like to ask for help on how to fix this. I would
Good morning! I would like to ask some help from you guys on how
I would like to ask for a reccomended solution for this: We have a
I would like to ask is there any way to achieve this functionality: I

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.