File I/O in a Visual C++ GUI

Hi everyone, I've been trying to figure out how to make, for example a button in Visual C++ that can take some text from a textbox and save it as a file.

But I don't mean using SaveFileDialog, I want to have it where when the user presses the button it saves the file to a pre-programmed location, and the user wouldn't be able to see anything happen (apart from the file appearing in the location of course). I've tried to use #include <fstream>, but it just generates some errors (not compiling the program.

Any suggestions and advice would be appreciated as it would really help me out. Thanks in advance.
Last edited on
This is what I would do in Qt:

1. Create the button with the GUI tool.
2. Create the text box with the GUI tool.
3. Go to the pushbutton's "released" slot
4. Fill in the function like this:
void MainWindow::on_pushButton_released()
    QString str = ui->TextBox->toPlainText();
    std::ofstream fout("output.txt");
    fout << str.toStdString();

TextBox was the name of my box. ui is created by the GUI editor. Everything is now fully functional though I would have liked to use QFile to be consistent with replacing the standard library.

Sorry, I don't know much about Visual Studio forms.
Last edited on
Topic archived. No new replies allowed.