Yes I'm using Win32 API CreateFile() because I need to write and read to the file in the same time and
I tried a lot of times but I cannot do it with fstream.
I dont want to close and reopen the file all the time I want to leave it open.
Yes I'm using Win32 API CreateFile() because I need to write and read to the file in the same time and
I tried a lot of times but I cannot do it with fstream.
I dont want to close and reopen the file all the time I want to leave it open.
Using Windows 10 with Code Blocks and MingW.
What do you mean?Originally Posted by Ducky
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
Sorry, I meant that I need to write to it and read from it from time to time. It's a log file.
Using Windows 10 with Code Blocks and MingW.
perhaps you're confused about how log files are supposed to work. generally a log file is an output-only proposition. a program rarely reads back in its own log file.
In my case I need to do both. But what matters right now is that I couldn't do it with fstream.
I found a sample code that worked in itself but when I tried to implement it in my code it wasn't working.
But doesn't matter, no big deal.
Using Windows 10 with Code Blocks and MingW.
But you can:
fstream::fstream - C++ Reference
Looks like it's working this time, dont know what I did wrong last time. Thanks anyway. ;-)
Using Windows 10 with Code Blocks and MingW.
Interesting enough going from C to C++ would actually solve the issue by using std::string, though fundamentally I agree with the argument that coming from a high level language can be harder to understand low level optimization.
It always struck me as odd the null terminating string concept in C. I think the LV (length- value) notion would just have been better. So first bytes have the total length of the string and then you (the parser) knows how much you need to read. Same memory footprint for strings less than 255 bytes as well. A struct is even better of course.
To Elysia and Laserlight, unfortunately you cannot open a file in read & write mode, keep it open and tell the size of the file in C++.
Now I remember the reason why I didn't use fstream.
tellg() returning -1
Using Windows 10 with Code Blocks and MingW.
If you don't know how to use a tool, that is a problem with your lack of knowledge.To Elysia and Laserlight, unfortunately you cannot open a file in read & write mode, keep it open and tell the size of the file in C++.
No. You didn't. You didn't have a reason for not using `fstream'.Now I remember the reason why I didn't use fstream.
You've found an area where you lack knowledge and are now trying to justify an preconceived notion.
Soma