I've got this code that uses an fstream to read and write to a file. The fstream object is held as a member of an object, and is initialized in the constructor like so:
idmap.open(path, std::fstream::in | std::fstream::out | std::fstream::app);
The file gets properly created if it doesn't already exists. Then it gets written to like so:
idmap.seekp(0, std::fstream::end);
idmap << str.size() << ':' << str << '\n';
idmap.flush();
idmap.sync();
It's supposed to be read like this but I don't know if it works because the file has always been empty:
idmap.seekg(0);
while (!idmap.eof()) {
idmap.getline(line, 1024);
idtype id = getIDMapEntry(std::string(line));
if (identifier.compare(nfile.getIdentifier()) == 0) {
return nfile;
}
}
Then it's closed when the program exits:
idmap.close();
It's probably something else in the program but I figure I'll ask here in case I did something stupid, and dig through everything else in parallel.