Hi there forum.
I'm making a program to edit ID3 tags in a mp3 file, and I use the fstream to handle the data.
When the message for "Open file" in the menu is recieved it calls a open file dialog. After that it calls a simple function to test that the fstream is working.
My problem is that the function does not work. But I've discovered that it works if I call the function in the main program before the message loop.
I have seperated my code a lot to get a better overview, but that shouldn't have an effect.
Here is the simple function:
1 2 3 4 5 6 7 8 9
void print_info(const TCHAR *filename) { //pointer filename is not to be used yet.
fout.open("test.txt", std::ios::out | std::ios::binary); //Simple test run.
if(fout.is_open()) {
fout.write("testing",7);
fout.close();
}
}
How is fout declared? Try not to call open/close on file streams. Instead construct/destroy the actual stream instead. Remember they're objects, not wrappers for open/close.
fout is declared std::ofstream fout;
And I discovered what actually happens. It creates the file in the directory for the file I selected in the dialogbox. How comes that?