0

The code I have does not write to a text file even after establishing a text file in the code and using several write methods.

I am using a window GUI maker. The GUI consists of four buttons that are change a label. The problem occurring is that after closing the GUI, the value of the button that was last pressed is supposed to be saved into a text file, however, the code does not save it. Here is an example of on of the buttons.

private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
//label3->Text = "Winter";
//vector<String> stringList;
//stringList.push_back("");
fstream stringFile;
sudden = "Winter";
label3->Text = sudden;
stringList.push_back("Winter");
stringFile.open("lastButton.txt", fstream::app);
for (int i = 0; i < stringList.size(); i++) {
    stringFile << "Winter. /n";
}
stringFile.close();
} 
JaysPT
  • 1
  • Are you looking at the right place for the file? Perhaps the [*working directory*](https://en.wikipedia.org/wiki/Working_directory) of your process is not what you expect it to be? What happens if you use an absolute path instead? And have you tried checking that the file is opened correctly? And have you tried to use a [*debugger*](https://stackoverflow.com/questions/25385173/what-is-a-debugger-and-how-can-it-help-me-diagnose-problems) to see what really happens? – Some programmer dude Feb 13 '23 at 14:51
  • https://stackoverflow.com/a/4712415/1196549 –  Feb 13 '23 at 15:16
  • @Someprogrammerdude: a debugging session would just confirm that nothing is written. –  Feb 13 '23 at 15:17

0 Answers0