![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
PFO God In Training
![]() Join Date: Jun 2005
Location: near St Louis, MO. (USA)
Posts: 549
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: 549
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 |
|
Expert Programmer
Join Date: Dec 2004
Posts: 794
Rep Power: 4
![]() |
Does WIndows even allow wide-character filenames?
|
|
|
|
|
|
#5 |
|
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.
|
|
|
|
|
|
#6 |
|
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.
|
|
|
|
|
|
#7 | |
|
PFO God In Training
![]() Join Date: Jun 2005
Location: near St Louis, MO. (USA)
Posts: 549
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 6:40 PM. |
|
|
|
|
|
|
#8 | ||
|
Newbie
Join Date: May 2005
Posts: 5
Rep Power: 0
![]() |
Quote:
Quote:
|
||
|
|
|
|
|
#9 |
|
PFO God In Training
![]() Join Date: Jun 2005
Location: near St Louis, MO. (USA)
Posts: 549
Rep Power: 4
![]() |
That makes no sense -- Windows (and possibly others) have wfopen() which takes a wchar_t* for filename. So why can't fstreams? And from what little I could find about it with google, there is apparently a C ANSI standard for it.
|
|
|
|
|
|
#10 | ||
|
Newbie
Join Date: May 2005
Posts: 5
Rep Power: 0
![]() |
Looks like today is my quote day :p
This is taken from POSIX standard (IEEE Std 1003.1, 2004 Edition ) Quote:
Quote:
Are you sure wfopen is a standard function? For example the POSIX standard mentioned above does not contain such a function. |
||
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|