How to select current directory?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

//Read picture
	string line;
	ifstream myfile ("/Users/XXXXX/Desktop/MathScripts/Proportions/Value Finder/picture.txt");
	if (myfile.is_open())
	{
		while (! myfile.eof())
		{
			getline (myfile,line);
			cout << line << endl;
		}
		myfile.close();
	}
	else cout << "Unable to load picture!!!" << endl;
	//Finish reading picture 


If I use just plain picture.txt for the directory it doesn't work, even though the executable is in the same folder as the .txt

If I move anything around, the txt doesn't load.
I also want to give this to friends, and their names aren't the same as mine xD


How would I "select" the current directory as where picture.txt is?
You should be able to just use "picture.txt". It will look for the file in your program's working directory, which may not be the same as where the exe is.

If you're using a VC++ project, put it in the project directory when you run it from VC++, and next to the exe when you double click the exe.
Sadly not. I am Mac - it's complicated.

I can't just use picture.txt, I need an actual directory.

Could the program find its current directory with system("pwd") and find the file there?
Unless you have some weird nonstandard compiler, I'm pretty sure almost all C++ language implementations and operating systems use the program's working directory to find files specified only by name.

What happens if you use "./picture.txt"? If it works, then "picture.txt" should too and you've got some serious weirdness going on.
@L B

Doesn't work.

I use CodeRunner for Mac.
Assuming you know the basic controls of the terminal, open one up and go to the directory where your executable is located.

Once inside the directory, type "ls" and make sure you can see both the executable and the picture.txt

type cd../

type chmod u+r+w+x "directorynamehere"

again, go into the directory and type g++ -W "c++ filename here" -o "exec filename here"
No quotes

type ./"exec filename here"

Paste the output here if it doesn't work
Topic archived. No new replies allowed.