[std][msvc++][vs2005sp1] unable to open iostream with greek letters in path name
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
You might want to learn a bit about unicode. Without
it, your filename is treated using a codepage. In C++,
the support goes through wchar_t, wifstream,
wofstream, etc.
Boost has some unicode support, but as far as I
remember the filename library didn't have it. It's
been more than a year since I last checked, though.
Hope it helps,
--Hector
--- TOL Tsagarakis Manos
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
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::vectorstd::string vecContents;
std::copy(std::istream_iterator
(ifs ), std::istream_iterator (), std::back_inserter(vecContents)); for (size_t i=0; i
cout << vecContents.at(i) << endl;
ifs.close();
}
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users ---------------------------------- __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com
Thanks Hector,
I believe I found a solution to the problem here:
http://forums.microsoft.com/msdn/ShowPost.aspx?PostID=145439&SiteID=1
that is calling setlocale(LC_CTYPE, "");
once at the beginning of the program.
It seems ok for now. At this time I don’t want to bother with Unicode stuff ...
Manos
-----Original Message-----
From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of Hector C.
Sent: Wednesday, April 25, 2007 3:42 PM
To: boost-users@lists.boost.org
Subject: Re: [Boost-users] [std][msvc++][vs2005sp1] unable to open iostream with greek letters in path name
You might want to learn a bit about unicode. Without
it, your filename is treated using a codepage. In C++,
the support goes through wchar_t, wifstream,
wofstream, etc.
Boost has some unicode support, but as far as I
remember the filename library didn't have it. It's
been more than a year since I last checked, though.
Hope it helps,
--Hector
--- TOL Tsagarakis Manos
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
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::vectorstd::string vecContents;
std::copy(std::istream_iterator
(ifs ), std::istream_iterator (), std::back_inserter(vecContents)); for (size_t i=0; i
cout << vecContents.at(i) << endl;
ifs.close();
}
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users ---------------------------------- __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (2)
-
Hector C.
-
TOL Tsagarakis Manos