C++ ifstream on XCode: Where is the default directory? -


OK, so this is the first time I have coded the encoded (I have been used for OBC) Has started a programming course in.

I am trying to open a file (with hard work in the console or from user input) and whatever I try, open T (through error checking) < P> I'm assuming this because I do not have the test.txt file in the root directory, so if so what is the root directory?

So far my code is:

  // Includes files #include & lt; Iostream & gt; # Include & lt; Stdio.h & gt; # Include & lt; Fstream & gt; using namespace std; // Global Variable Short Impact [512] [512]; Small output image [512] [512]; // function prototype zero getInput (four *, four * out); Zero initializeArray (ifstream * input); // main int main () {// local variable char inputFile [32]; Four output files [32]; Instream input; Offstream output; GetInput (inputFile, outputFile); Cout & lt; & Lt; Input file & lt; & Lt; Endl; // test which was sent back from input input. Open (inputfile, ifstream :: in); If (! Input.is_open ()) {// to check that the file exists cout & lt; & Lt; "File not found! \ N"; Return 1; // if not found, end program} initializeArray (& amp; input); Return 0; } // end main // user initial input from zero getInput (four * in, four * out) {cout & lt; & Lt; "Please specify input file:"; Cin & gt; & Gt; In; Cout & lt; & Lt; "\ NPlease specify an output file:"; Cin & gt; & Gt; outside; } // and getInput // Input file sets global array for information on zero initialized array (ifstream * input) {} // end initializeArray   

Please tell me if something else I'm wrong, because I'm sure it's always a big possibility :)

default The directory should be the working directory of the application, which is usually located in one place (debuggers sometimes mess with it) Can).

For simple testing, just specify a complete path (or code) in the command line.

Existing directory (viewable), getcwd () C function (also usable in C ++) will be helpful. Something like this:

  four * dir = getcwd (zero, 0); // Platform-dependent, see the reference link below printf ("current DIR:% s", DIR);   

It should display in the console There are some differences in the getcwd function that you run on, I have not tested it on Mac, but the information here:



Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

c# - Confused over DLL entry points (entry point not found exception) -