Jump to content

  • Log In with Google      Sign In   
  • Create Account

ifstream loading binary files default path?


Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
6 replies to this topic

#1   Members   

225
Like
0Likes
Like

Posted 25 January 2014 - 08:11 PM

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, 25 January 2014 - 08:12 PM.


#2   Moderators   

9738
Like
1Likes
Like

Posted 25 January 2014 - 10:09 PM

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, 25 January 2014 - 10:11 PM.

zlib: eJzVVLsSAiEQ6/1qCwoK i7PxA/2S2zMOZljYB1TO ZG7OhUtiduH9egZQCJH9 KcJyo4Wq9t0/RXkKmjx+ cgU4FIMWHhKCU+o/Nx2R LEPgQWLtnfcErbiEl0u4 0UrMghhZewgYcptoEF42 YMj+Z1kg+bVvqxhyo17h nUf+h4b2W4bR4XO01TJ7 qFNzA7jjbxyL71Avh6Tv odnFk4hnxxAf4w6496Kd OgH7/RxC

#3   Members   

225
Like
0Likes
Like

Posted 25 January 2014 - 10:15 PM

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, 25 January 2014 - 10:15 PM.


#4   Members   

225
Like
0Likes
Like

Posted 25 January 2014 - 10:28 PM

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.



#5   Moderators   

21387
Like
0Likes
Like

Posted 25 January 2014 - 11:55 PM

You want Working Directory in the Debugging section of Project Properties.
Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

#6   Members   

225
Like
0Likes
Like

Posted 26 January 2014 - 12:02 AM

Whoops wrong place. I did it in General lol. Thanks for the fix.



#7   Members   

3177
Like
1Likes
Like

Posted 26 January 2014 - 12:43 AM

When you are using VS to run it, the directory won't default to the .exe one, but outside of VS, running stand-alone, it should default to your .exe.






Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.