• Advertisement
Sign in to follow this  

ifstream loading binary files default path?

This topic is 1454 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm trying to load a binary file, and after testing to see if it passed, it fails every time. I assumed just putting the file name in the quotes would assume the default path of the exe. For example, lets say your exe is stuffed away in some folder such as C:\Programming\Loading Binary Files\ and you have a file called test.bin in the same folder as the exe. It still fails with this simple code:

#include <iostream>
#include <fstream>
using namespace std;

int main()
{
	ifstream file ("test.bin", ios::in | ios::binary);
	if(file)
	{
		cout << "passed" << endl;
		file.close();
	}
	else
		cout << "fail" << endl;
	
	system("pause");
	return 0;
}

So without having to type an entire path of the test.bin, what is the default path of the file assuming if you were to just put the file name in quotes and not a full file path? Thanks in advance.

Edited by Psychopathetica

Share this post


Link to post
Share on other sites
Advertisement
The working directory in default Visual Studio C++ projects is the directory containing the project file. You can change the working directory to be the executable directory by setting it to $(OutDir). Don't forget to also set this for the Release mode configuration as well, if you haven't already selected "All Configurations". Edited by fastcall22

Share this post


Link to post
Share on other sites

Nvm. I found the file needed to be with the .cpp files, not the debug directory where your exe is located.

 

[EDIT] Hmmm interesting. I'm changing that now

Edited by Psychopathetica

Share this post


Link to post
Share on other sites

Well I tried setting the $(OutDir)\ in the Configuration Properties > Output Directory and also have my project in Release mode rather than Debug and it still wont read the file within the path of the exe. Unless I missed something. I dont plan on keeping the file within my source code files forever.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement