wifstream & locale

Discussion in 'C++' started by koara, Feb 5, 2008.

  1. koara

    koara Guest

    Hello all,

    I needed to read contents of an UTF8 encoded file in C++ (gcc version
    3.3.5 on Linux). I decided to do it the C++ way, using streams:

    -------------
    std::locale utf8loc("en_US.utf8");
    std::wifstream ifs("smthg");
    ifs.imbue(utf8loc);
    std::wstring item;

    while (ifs >> item) {
    here
    }

    ------------

    but the inner block ("here") never gets executed. I tried searching
    around the web and my head spins, surely doing such mundane,
    straightforward task cannot be that complicated in C++? What am I
    doing wrong please? What should I test for, look out for?

    Cheers.

    To narrow down my problem:
    * I don't want to use any non-standard functions, libraries etc.
    * the input file is in UTF8, I want to read (parts of) its contents as
    wstring

    ---------------
    $ locale -a
    C
    POSIX
    en_GB.utf8
    en_US.utf8
     
    koara, Feb 5, 2008
    #1
    1. Advertising

  2. koara

    Christopher Guest

    On Feb 5, 7:53 am, koara <> wrote:
    > Hello all,
    >
    > I needed to read contents of an UTF8 encoded file in C++ (gcc version
    > 3.3.5 on Linux). I decided to do it the C++ way, using streams:
    >
    > -------------
    > std::locale utf8loc("en_US.utf8");
    > std::wifstream ifs("smthg");
    > ifs.imbue(utf8loc);
    > std::wstring item;
    >
    > while (ifs >> item) {
    > here
    > }
    >
    > ------------
    >
    > but the inner block ("here") never gets executed. I tried searching
    > around the web and my head spins, surely doing such mundane,
    > straightforward task cannot be that complicated in C++? What am I
    > doing wrong please? What should I test for, look out for?
    >
    > Cheers.
    >
    > To narrow down my problem:
    > * I don't want to use any non-standard functions, libraries etc.
    > * the input file is in UTF8, I want to read (parts of) its contents as
    > wstring
    >
    > ---------------
    > $ locale -a
    > C
    > POSIX
    > en_GB.utf8
    > en_US.utf8


    Mayhaps the file "smthg" does not contain text that is convertable to
    a wstring? or no text at all?
    What's in the file? Also did you ever check if it actually got opened?
    Is it in the proper directory?
     
    Christopher, Feb 5, 2008
    #2
    1. Advertising

  3. koara

    koara Guest

    On Feb 5, 5:15 pm, Christopher <> wrote:

    > Mayhaps the file "smthg" does not contain text that is convertable to
    > a wstring?


    No. It contains text convertible to wstring.

    > What's in the file? Also did you ever check if it actually got opened?


    Yes I did, problem is not in file opening.
    File contains text with national characters (cz, de).

    Cheers.
     
    koara, Feb 6, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Maurice Hulsman
    Replies:
    1
    Views:
    1,921
    Guus Bosman
    Jul 25, 2004
  2. Ben Hetland

    ifstream and wifstream - combined

    Ben Hetland, Sep 20, 2005, in forum: C++
    Replies:
    0
    Views:
    679
    Ben Hetland
    Sep 20, 2005
  3. anubis
    Replies:
    2
    Views:
    1,337
    anubis
    Mar 21, 2006
  4. toton

    wstring & wifstream

    toton, Sep 29, 2006, in forum: C++
    Replies:
    9
    Views:
    2,582
    =?iso-8859-1?q?Kirit_S=E6lensminde?=
    Oct 2, 2006
  5. Ioannis Vranos

    wifstream/wofstream names

    Ioannis Vranos, Sep 30, 2008, in forum: C++
    Replies:
    1
    Views:
    732
Loading...

Share This Page