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.
Printable View
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.
What do you mean?Quote:
Originally Posted by Ducky
Sorry, I meant that I need to write to it and read from it from time to time. It's a log file.
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.
But you can:
fstream::fstream - C++ Reference
Looks like it's working this time, dont know what I did wrong last time. Thanks anyway. ;-)
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.
http://cboard.cprogramming.com/cplus...rning-1-a.html
If you don't know how to use a tool, that is a problem with your lack of knowledge.Quote:
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'.Quote:
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