Boost logo

Boost Users :

From: TOL Tsagarakis Manos (mtsagara_at_[hidden])
Date: 2007-04-24 02:08:29


Hello everyone,

 

I know this is not a boost related issue, but I hope someone has a solution.

The question is very simple and should not even be asked:

 

“How can I open a file using std::iostreams, if the files full path, contains Greek letters (or probably any other language except English)?”

 

The test case below shows part of the problem as it successfully opens the file using std::oftream and writes some Greek in it.

Then I can read back its contents using std::ifstream. Now the file name in windows explorer or command line should be "ελληνικό όνομα αρχείου.txt" (in case you can't read this, it is "greek file name.txt"). But instead it becomes "åëëçíéêü üíïìá áñ÷åßïõ.txt"

 

Actually when this is done by a full MFC application it is impossible to open the file! I get assertion failure!

 

I use MS Visual Studio 2005 sp1 and std lib and CRT that comes with it.

 

Has anyone faced this problem before?

Do I have to do something special in order to be able to use standard iostreams library with Greek file names?

 

 

Thank you in advanced,

 

Emmanuil Tsagarakis

 

 

 

 

 

 

 

// test_greek_filenames.cpp compile with: /EHsc

#include <iostream>

#include <fstream>

#include <iterator>

#include <algorithm>

#include <string>

#include <vector>

#include <assert.h>

 

using namespace std;

 

namespace {

    struct string_by_line : std::string

    {

    };

 

    std::istream & operator >> (std::istream & is, string_by_line & strLine)

    {

        getline(is, strLine);

        return is;

    }

 

    const string s_strFileName("ελληνικό όνομα αρχείου.txt"); }

 

int main(int argc, char **argv)

{

    ofstream ofs;

    ofs.open(s_strFileName.c_str());

    assert(ofs.good());

    ofs << "Writing to file ..." << endl;

    ofs << "Ελληνικά περιεχόμενα στο αρχείο (greek file contents) ..." << endl;

    ofs.close();

 

    ifstream ifs;

    ifs.open(s_strFileName.c_str());

    assert(ifs.good());

 

    std::vector<std::string> vecContents;

    std::copy(std::istream_iterator<string_by_line>(ifs ), std::istream_iterator<string_by_line>(), std::back_inserter(vecContents));

    for (size_t i=0; i<vecContents.size(); ++i)

        cout << vecContents.at(i) << endl;

    ifs.close();

}

 

 

 

 

 

 

 



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net