Codeblocks creates simple text file in home folder instead of creating it in project folder

故事扮演 提交于 2020-03-06 10:57:48

问题


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 Here is my code:

#include <iostream>
#include <fstream>

using namespace std;

int main()
{
    ofstream MyFile ("filename.txt");
    MyFile<< "Hey this is my file" << endl;
    MyFile.close();
    return 0;
}

来源:https://stackoverflow.com/questions/60366124/codeblocks-creates-simple-text-file-in-home-folder-instead-of-creating-it-in-pro

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!