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 Psychopathetica   Members   -  Reputation: 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 fastcall22   Crossbones+   -  Reputation: 8916

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.

gzip: H4sIAAAAAAAEAG1QTUvEMBC991e8nvaiFfYoS7yo sLCo6MnjtJ1ugmkiyWRL/72z3T1YEQIJ8z4zA2Xp yPvt1qBpGrRFIJZkk9FyRyUzHCbKIHgn4hnZOrm1 TD0mG0HCCs+QGDGWziKXI6Wm2n++GYwUVH2mrGEE PnGCVQ8K8+JYfXA6URDEQfMZh5h6g5eoAlWJdeEI bbH2qYZf7XMUfw8f/Q0oMeZYNL9/WHF0uFEshvMr XYujd9SycFb+F18QcSOvlJauZ8ejqevdnV7/d550 e0t6prmunh73Bu+vz4c/XUeOQXfJgvKNkhf95U8/ Dtgmy5IBAAA=

#3 Psychopathetica   Members   -  Reputation: 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 Psychopathetica   Members   -  Reputation: 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 ApochPiQ   Moderators   -  Reputation: 20087

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 Psychopathetica   Members   -  Reputation: 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 Dragonsoulj   Crossbones+   -  Reputation: 3077

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.




PARTNERS