Note
I would fix Visual Studio on your laptop.
Nevertheless, you can use OnlineGDB to write and test some simple projects.
The Problem
Let me see if I understood your problem correctly.
You have a file, let's call it myfile.txt. You would like to (read? and) write to this file.
The Solution
Yes, you can use fstream, however, the program compile and run by OnlineGDB can only access files that are on the server.
Fear not though, as you can add any files to your project. There are a "New File" and an "Upload File" icons next to the "Run" button. With the help of these, you can upload and download files as part of your projects. You can also download files if you click on the tab representing your file.
I've made a small sample project for you. You will see that the program reads the content of myfile.txt then adds an extra line to it which you can see change in the editor after the program ran.
Here's the source below (copied from the project linked above):
main.cpp
#include <fstream>
#include <iostream>
static void ReadFile()
{
std::ifstream file("myfile.txt");
std::string line;
if (!file.is_open())
return;
while (std::getline(file, line))
std::cout << line << std::endl;
file.close();
}
static void WriteFile()
{
std::ofstream file("myfile.txt", std::ios_base::app);
if (!file.is_open())
return;
file << "Another line added" << std::endl;
file.close();
}
int main()
{
ReadFile();
WriteFile();
return 0;
}
myfile.txt (before running the program)
Hello world!
This is a test.
myfile.txt (after running the program)
Hello world!
This is a test.
Another line added