![]() |
std::fstream Is not writing :(
This is making me go insane, for some reason nothing is being written when I call std::fstream::write or std::fstream::put.
It's gotta be something simple but I'm just not seeing it, thanks in advance for any help :D. Code:
// Opens the crash check file, returns true if success |
Re: std::fstream Is not writing :(
What happens? Crash? lockup? Or just nothing... and nothing in the file?
|
Re: std::fstream Is not writing :(
The file has 0 bytes in it, that makes absolutely no sense at all.
I did a couple of lines with ofstream and the << operator and that worked but unfortunately not in binary mode. I got rid of all that C++ file i/o crap out of frustration and went back to the C style fopen way of doing it, doesn't seem to like reading bools though. I still wish I knew why it didn't write, all my other code is using C++ file i/o and works perfectly ( though maybe thats because its only reading ). |
Re: std::fstream Is not writing :(
omg, messy code.
Why do you have pointers to fstream ? Tell me what precisely this function should do and I'll fix it. after new, check !m_fCrashstatus is totally useless. If allocation fails, exception will be thrown. eof doesn't return true if file size is 0. use std::fstream::binary instead of std::ios.binary, same for other types. write ("Test!\n", 6), not write("Test!\n", 7). you cannot assume that \n is 2 characters. If you want to write \n, use text mode. |
Re: std::fstream Is not writing :(
1. Yeah, its only that function though all the others are much cleaner.
2. It wasn't always like that, I changed it a while ago just for the hell of it to see if it would work ( bored at the time, and it was late ) 3. Hmm, thats new... Thanks for that info. 4. Again, never knew that or have forgotten it since I hadn't used C++ i/o in a long time. 5. Ok 6. That was leftover, I do know that \n is one character I was just accounting for the extra \0 that the compiler adds onto strings. The code I posted is a total hack I admit, I don't really smooth things out until I know its going to work. The plugin in general is supposed to detect if the server has crashed and change the map on the next restart. All it does is checks the content of a file at startup, if its 1 then the server exited cleanly. If it's 0 that means ServerDeactivate wasn't called and the server must have crashed so it chooses a random map from mapcycle.txt. |
Re: std::fstream Is not writing :(
Ok so here is some simple function
- server crashed if : file does not exists, file empty or first character in file is not '1' (0x31) - server clean if : file exists and first character in this file is '1' (0x31) Code:
bool Crashed () { |
Re: std::fstream Is not writing :(
Thanks!
That makes alot more sense now. |
Re: std::fstream Is not writing :(
Don't forget to flush the buffer contents - it may not be writing to the actual file because it's waiting for a more efficient time to swap it out of memory to the disk. fflush for some of the C file i/o, or just file.flush() for C++ I think.
|
Re: std::fstream Is not writing :(
when the file is closed, the buffers are flushed anyway, so don't waste too much buffering advantages by using flush everywhere :)
|
All times are GMT +2. The time now is 08:08. |
Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.