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

  • Home
  • SEARCH
  • 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 6253839
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T14:04:28+00:00 2026-05-24T14:04:28+00:00

I have a strange problem, I use wifstream a(a.txt); wstring line; while (a.good()) //!a.eof()

  • 0

I have a strange problem,
I use

wifstream a("a.txt");
wstring line;
while (a.good()) //!a.eof()  not helping
{
     getline (a,line);
      //...
     wcout<<line<<endl;

}

and it works nicely for txt file like this
http://www.speedyshare.com/files/29833132/a.txt
(sorry for the link, but it is just 80 bytes so it shouldn’t be a problem to get it , if i c/p on SO newlines get lost)
BUT when I add for example 水 (from http://en.wikipedia.org/wiki/UTF-16/UCS-2#Examples )to any line that is the line where loading stops. I was under the wrong impression that getline that takes wstring as one input and wifstream as other can chew any txt input…
Is there any way to read every single line in the file even if it contains funky characters?

  • 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-24T14:04:29+00:00Added an answer on May 24, 2026 at 2:04 pm

    The not-very-satisfying answer is that you need to imbue the input stream with a locale which understands the particular character encoding in question. If you don’t know which locale to choose, you can use the empty locale.

    For example (untested):

    std::wifstream a("a.txt");
    std::locale loc("");
    a.imbue(loc);
    

    Unfortunately, there is no standard way to determine what locales are available for a given platform, let alone select one based on the character encoding.

    The above code puts the locale selection in the hands of the user, and if they set it to something plausible (e.g. en_AU.UTF-8) it might all Just Work.

    Failing this, you probably need to resort to third-party libraries such as iconv or ICU.

    Also relevant this blog entry (apologies for the self-promotion).

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

Sidebar

Related Questions

I have one strange problem, if I use graphics.lineTo while moving the mouse (
I use the memcache extension for python, and I have a very strange problem.
I'm having a strange problem. I have to use GetPostBackEventRefence to force a Postback,
I have this very strange problem while compiling the project. MOC seems to be
I have strange problem: when I use mu repository stub I get strange exception:
I have come acrooss a very strange problem. I use a POST request for
I have a strange problem with my iPhone app. I use geolocation and push
I have strange problem. When I use @return Model\Article in the model-loading method then
I have a strange problem that i'm seeing in Chrome. I use an ajax
I have a very strange problem with Visual Source Safe. I use VSS as

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.