Search code examples
windowsstlstlport

How to port stlport ifstream(HANDLE) to MS stl ifstream?


I'm currently porting code from stlport 5.1.3 to stl with MSVS 2010. I'm facing a problem and I hope someone can help me.

Somewhere in the code is:

HANDLE lHandle = CreateFileW(...);

ifstream lStream( lHandle );

// more job here...

This builds with stlport because the basic_ifstream has a cTor that takes a void*. But standard stl doesn't. I should write something like:

ifstream lStream( /*FileName*/ );

...but my file name is a wchar_t *. ifstream cTor only takes char *...

Do you know a work around?

Thanks in advance,

Dominique


Solution

  • Well, it seems that stl included in MSVC2010 provides all the stuff I needed but it was not in the doc.

    CreateFile was use because the former std::fstream could not handle wide char file name. Now, it has a cTor and a open() member for that.

    Also, the new flavor of ifstream allows the programmer to set a sharing protection mode. I needed that also and it was done by CreateFile...

    Thus, the "new" stl give me all the power I needed. Just a little flaw in the doc.