2015-06-22 13:21 GMT+02:00 Etienne Sandré-Chardonnal <[email protected]
>:
> Hi,
>
> I have tried to open the file with _wfopen(), pass it to __gnu_cxx::
> stdio_filebuf<char>, and set it as the buffer of an std::istream.
> The file is open properly, first bytes are OK, but after 263 read bytes I
> get an eof(), while the file is 39MB large.
>
> Reading works well with a standard std::ifstream and a non-unicode file
> name, and I am testing the simplest way possible:
>
> int i = 0;
>
> while(!stream.eof())
>
> {
>
> char a;
>
> stream.read(&a, 1);
>
> i++;
>
> }
>
> info("%d",i);
>
>
> If nobody has an idea, I will give up for a Qt-based solution but I was
> hoping making a source code that would compile without any external library
> (with some preprocessing for detecting the Windows case)
>
>
That is not the right way to read from a C++ istream. Do something like
this:
std::size_t i = 0;
char a;
while(stream.read(&a, 1))
{
++i;
}
info("%d", i);
I.e. put the read action in the condition of the loop. Checking eof doesn't
get you what you want, see here:
http://stackoverflow.com/questions/5605125/why-is-iostreameof-inside-a-loop-condition-considered-wrong
Also, if you're using Qt anyways, it is indeed much preferred to use its
I/O system, so that you don't rely on a libstdc++ extension.
Cheers,
Ruben
------------------------------------------------------------------------------
Monitor 25 network devices or servers for free with OpManager!
OpManager is web-based network management software that monitors
network devices and physical & virtual servers, alerts via email & sms
for fault. Monitor 25 devices for free with no restriction. Download now
http://ad.doubleclick.net/ddm/clk/292181274;119417398;o
_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public