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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T07:09:36+00:00 2026-05-16T07:09:36+00:00

—- PLEASE CLOSE —- —— Edit ——— I found where the problem is. I’m

  • 0

—- PLEASE CLOSE —-

—— Edit ———

I found where the problem is. I’m going to start a new question for the real problem ….

———————-

 


Hi,

My Situation:

Linux (Ubuntu 10.04)
gcc

But it has to be platform independent

I have a text file (UTF-8) with special characters like ¥ © ® Ỳ È Ð. I have a std::map where I would like to have a datatype for the key to hold these special characters. Currently I’m using wchar_t.

Then I have to use strings, which can contain these chars. Now I’m using std::wstring.

I have to read that UTF-8 file. So, I thought using a wifstream. And for line processing, I used wstringstream.

I think this isn’t bad, what I’ve done so far… If not, what is better?

What is going wrong:

Of course, I have to read that file. But reading the lines stops at the first line with a special char. In short this is what I did:

map<wchar_t, Glyph*> glyphs;

//...

wifstream in(txtFile.c_str());
 if (!in.is_open())
 {
  throw runtime_error("Cannot open font text file!!");
 }
 wstring line;
 while (getline(in, line)) // edit
 {
  printf("Loading glyph\n");
  if (line.length() == 0)
  {
   continue;
  }
  wchar_t keyChar = line.at(0);
  /* First, put the four floats into the wstringstream */
  wstringstream ss(line.substr(2));
  /* Now, read them out */
  Glyph *g = new Glyph();
  ss >> g->x;
  ss >> g->y;
  ss >> g->w;
  ss >> g->h;
  glyphs[keyChar] = g;
  printf("Glyph `%c` (%d): %f, %f, %f, %f\n", keyChar, keyChar, g->x, g->y, g->w, g->h);

 }

So, the question is: How to read a file with the special chars with a wifstream?

Thanks in advance!

How the file looks:

  0.000000 0.000000 0.010909 0.200000
A 0.023636 0.000000 0.014545 0.200000
B 0.050909 0.000000 0.014545 0.200000
C 0.078182 0.000000 0.014545 0.200000
D 0.105455 0.000000 0.014545 0.200000
E 0.132727 0.000000 0.014545 0.200000

….

È 0.661818 0.400000 0.014545 0.200000
É 0.689091 0.400000 0.014545 0.200000
Ê 0.716364 0.400000 0.014545 0.200000
Ë 0.743636 0.400000 0.014545 0.200000
Ì 0.770909 0.400000 0.012727 0.200000
Í 0.796364 0.400000 0.012727 0.200000
Î 0.821818 0.400000 0.012727 0.200000
Ï 0.847273 0.400000 0.012727 0.200000
Ð 0.872727 0.400000 0.014545 0.200000
Ñ 0.900000 0.400000 0.014545 0.200000
  • 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-16T07:09:38+00:00Added an answer on May 16, 2026 at 7:09 am
    1. use while( !in ) instead of the eof variant, it’s better, see this question

    2. I’m assuming you’re using Windows (as Linux and Mac normally have native UTF-8 platform encoding, which allows you to ignore most of this stuff).

    What I would do is read the whole file as chars and convert it to wchar_t‘s using the handy functions in this question by me :).

    Remember: on linux (and probably mac os x too) you can just output a UTF-8 stream to a terminal and get the right characters, in Windows, that’s a whole different kond of story.

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

Sidebar

Related Questions

So to start, I have an array of XML files. These files need to
&mdash; or &#8212; Is there a difference between these? Is one better-supported than the
I'm using a DatePicker ( org.apache.wicket.extensions.yui.calendar.DatePicker — Javadoc ) in a form. The form
I'm having a simple problem toggling between +/- characters which prepend a link which
This is a follow-up to the question: Should the folders in a solution match
I am currently running into a problem where an element is coming back from
string formIdList = 8256, 8258, 8362, 8120, 8270, 8271, 8272, 8273, 8257, 8279, 8212,
I'm trying to write a web application using the new offline capabilities of HTML5.
Bit of an odd question. I'm using cocoa. I have a series of numbers
This is an interesting problem that I have searched here and all over my

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.