Thread: changing directory of io files

  1. #1
    Registered User
    Join Date
    Sep 2002

    changing directory of io files

    i am trying to read/write to/from two separate files, my code works as long as i execute it from the Visual C++ platform. when i double click on the exe file in the debug folder it doesn't write to the specified file. i think it has to do with the path names. my question is how to i define the path name completely? as in "H:\C2plus\monte_carlo\results.txt" ?

    the portion of my code is as follows:
    #include <iostream>
    #include <cmath>
    #include <cstdlib>
    #include <fstream>
    #include <time.h>
    using namespace std;
    const char * filei="simMC1.txt";
    const char * fileo="resultsMC.txt";
    int N,call_put;
    double X, TP, T, t1, z, r, So, Pavg, volatility;
    double randaud(); 
    int main ()
    	//read in file (call_put,N,TP,So,X,r,volatility)
    	ifstream infile(filei,ios::in);
    	ofstream outfile(fileo,ios: : out);
    	if(! infile.is_open())
    		cout << "error";
    outfile << Pavg << endl;
    return 0;
    any help would be great!
    Last edited by aarnal; 09-11-2002 at 10:59 AM.

  2. #2
    Used Registerer jdinger's Avatar
    Join Date
    Feb 2002

    notice the double backslashes

  3. #3
    Registered User
    Join Date
    Sep 2002

    thank you

    thank you for your help, the solution is always so easy.

  4. #4
    Banal internet user
    Join Date
    Aug 2002
    double backslashes \\ are a commonly overlooked cause of error for many novice and advanced C/C++ programmers

    uhm... why did I reply to this again?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Reading .dat files from a folder in current directory...
    By porsche911nfs in forum C++ Programming
    Replies: 7
    Last Post: 04-04-2009, 09:52 PM
  2. All files in a directory
    By cloudy in forum Linux Programming
    Replies: 1
    Last Post: 06-09-2008, 01:50 AM
  3. How can i check a directory for certain files?
    By patrioticpar883 in forum C++ Programming
    Replies: 13
    Last Post: 02-01-2008, 05:27 PM
  4. Finding out the name of a file, and changing directory
    By nindoja in forum C Programming
    Replies: 17
    Last Post: 06-22-2004, 09:49 PM
  5. Dos commands hehe
    By Carp in forum A Brief History of
    Replies: 2
    Last Post: 01-17-2003, 02:51 PM