changing directory of io files

This is a discussion on changing directory of io files within the C++ Programming forums, part of the General Programming Boards category; i am trying to read/write to/from two separate files, my code works as long as i execute it from the ...

  1. #1
    Registered User
    Join Date
    Sep 2002
    Posts
    2

    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:
    Code:
    #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";
    		exit(1);
    	}
    
    
                                              ....
    
    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
    Posts
    1,065
    H:\\C2plus\\monte_carlo\\results.txt

    notice the double backslashes

  3. #3
    Registered User
    Join Date
    Sep 2002
    Posts
    2

    thank you

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

  4. #4
    BMJ
    BMJ is offline
    Banal internet user BMJ's Avatar
    Join Date
    Aug 2002
    Location
    Chicagoland
    Posts
    1,380
    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, 04: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 Cprogramming.com
    Replies: 2
    Last Post: 01-17-2003, 01:51 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21