![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
PFO God In Training
![]() Join Date: Jun 2005
Location: near St Louis, MO. (USA)
Posts: 599
Rep Power: 4
![]() |
UNICODE and ifstreams
my VC++ 6.0 MFC program is compiled for UNICODE. I have a std::wstring object that contains a filename. I tried to use wifstream in(filename.c_str()) but got error that the compiler can't convert the first parameter from wchar_t* to char*. Is there another way to do it without explicitly converting it myself? If not, how do people using other languages use anything from the fstream STL library, or is the C-style FILE the only way?
Thanks |
|
|
|
|
|
#2 |
|
Programmer
Join Date: Jun 2005
Posts: 86
Rep Power: 4
![]() |
Darn site keeps going up and down. Anyway, one way to do this is to convert the filename to type string like this:
#include <string>
#include <fstream>
#include <iostream>
using namespace std;
int main(void) {
wstring filename = L"string.cpp";
string s_filename(filename.begin(), filename.end());
wifstream in(s_filename.c_str());
wstring line;
while (!in.eof()) {
getline(in, line);
wcout << line << endl;
}
in.close();
return 0;
} |
|
|
|
|
|
#3 |
|
PFO God In Training
![]() Join Date: Jun 2005
Location: near St Louis, MO. (USA)
Posts: 599
Rep Power: 4
![]() |
I don't want to convert to ascii -- what if the filename is Chinese or Japanese, or some other language that doesn't fit in ascii???
|
|
|
|
|
|
#4 |
|
Programmer
Join Date: Jun 2005
Posts: 86
Rep Power: 4
![]() |
BTW, I forgot to mention that the solution above is not necessarily portable either. Also, if the filename is something in japanese or whatever, wifstream fails. Several people have proposed fixes to the STL library for this. Apparently, one of the things holding this up is that several filesystems don't actually support unicode.
|
|
|
|
|
|
#5 |
|
Programmer
Join Date: Jun 2005
Posts: 86
Rep Power: 4
![]() |
BTW dinkumware (the guys that Microsoft uses for their STL implementation) apparently has a lib that supports wifstream with a wchar_t * filename.
|
|
|
|
|
|
#6 | |
|
PFO God In Training
![]() Join Date: Jun 2005
Location: near St Louis, MO. (USA)
Posts: 599
Rep Power: 4
![]() |
well, thanks for the comments. Not what I wanted to hear, so I guess I'll have to use wfopen() and associated functions.
Not supporting UNICODE is a lousy excuse for not fixing wifstream() -- there are a lot of other STL unicode classes too, such as wstring that don't work on os without unicode support. Quote:
Last edited by Ancient Dragon; Jun 13th, 2005 at 7:40 PM. |
|
|
|
|
|
|
#7 |
|
Expert Programmer
Join Date: Dec 2004
Posts: 794
Rep Power: 4
![]() |
Does WIndows even allow wide-character filenames?
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|