Hi everyone.
I have a problem, It seems that the default directory for the files I want to read or write in is set on my Users directory (on mac).
I would like to be able to write relative path from somewhere inside my project folder. (On Xcode, the defaut settings for the files was the same folder as the .exe)
I've searched on forums and I read that changing the Execution Working Directory can resolve, but actually it doesn't (maybe I'm doing it wrong)
I'm with macOs 10.6.8 and code::blocks 13.12 (the latest I found for mac)
So here's my C++ code :
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ofstream monFlux("testReadFile.txt");
if(monFlux)
{
cout<<"ok!"<<endl;
monFlux<<"it works!!"<<endl;
}
else
{
cout<<"error file opening"<<endl;
}
return 0;
}
writing only the name of the file, it is created in /Users/myname/
So I tried to changed this Project>Properties>Build Targets >Execution Working Directory
it was .
I change to the absolute path I wanted as a root : /Users/myname/Documents/Programmation/LearningCpp/testReadFile/bin/Debug
here it propose two options relative or absolute, I tried both, the result is always the same, the file is created in /Users/myname/
If someone can help me I would be really grateful!
Thank you very much,
Rub
Thank you for your answer!
This should be the correct setting for the project...
Do you mean that the absolute path I set in the project properties should be the right way to do that?
But I have the same results with the three different paths I tried to set in the project properties...
char *path = NULL;
size_t size;
path = getcwd(path,size);
cout<<path;
free(path);
path always results /Users/username
I searched a bit the nightly build but it seems that 13 is the earliest for mac. I'll search more info maybe on mac code blocks users forums (does that even exist??)
If anyone has a clue, please help!
Thanks anyway :)