dimanche 23 février 2020

Codeblocks creates the text file in the home folder, instead of creating it in the Project folder. (Mac)

So basically, I'm using CodeBlocks 13.12 on my mac. So when I try and run this code, it creates the file (filename.txt) in my home directory. However, I need it to create the file in my project folder instead as it does in windows. (for assignment purposes) Here's a list of things I do not want: 1)No additional code can be added. 2)I don't want to add an absolute path as it would not work in Windows.

Here's what I want: I just want a setting the allows me to create the text file in my project folder instead. Mind the fact that all other files (cpp and headers) are created in the project folder. But just not this.

I've found some people addressing the same problem however, the solution wasn't much useful to me. I'm adding some links so that you can get a good idea of my problem. Feel free to ask more in the comments! http://forums.codeblocks.org/index.php?topic=21767.0 How Do I Set the Working directory on Code::Blocks on Mac?

#include <iostream>
#include <fstream>

using namespace std;

int main()
{
    ofstream MyFile ("filename.txt");

    MyFile<< "Hey this is my file" << endl;

    MyFile.close();

    return 0;
}

Aucun commentaire:

Enregistrer un commentaire