Is it possible for a specific unit / desktop to be unable to execute ofstream?

42 Views Asked by At

So I am a second year computer science student and tinkering with a personal project as a practice before our school activity. I am trying to be familiar with the fstream header. Now, I (or my computer / compiler) has no problem with ifstream. I can read contents of my text files just fine. My problem is with ofstream. It can't create or open text files. The .is_open function always returns false. Here's a copy of a part of my code.

void save() {

        fstream pData;
        pData.open("./files/characters.txt");

        if (!pData.is_open()){
            cout << "can't access / make file";
        }

        pData << flush;
        pData.close();
    }

Everytime I run my code the if statement will return true, which means the file is not created or cannot be opened. I thought I only had a problem on that project only, so I tried making another file with a new ofstream code. It didn't work. I also tried copying working ofstream codes online but it still didn't work on my pc. Am using Code::Blocks 20.03. Please help T^T

0

There are 0 best solutions below