LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Need help Trying to open or run a file/program through a c++ program (https://www.linuxquestions.org/questions/programming-9/need-help-trying-to-open-or-run-a-file-program-through-a-c-program-782514/)

xskycamefalling 01-15-2010 09:49 PM

Need help Trying to open or run a file/program through a c++ program
 
Ok so Basically i have 2 questions

1. i know how to create a file with c++ using
but is there a way to save it to a specific location on your computer with windows and linux if you could please
Code:

ofstream myfile;
myfile.open("newfile.txt");
myfile <<"Bla";
myfile.close();

2. i need to know how to run/execute/open a file in a c++ program
im using and its not working
Code:

ifstream file;
      file.open("newfile.txt");

thanks to all in head of time.

neonsignal 01-16-2010 12:24 AM

Quote:

1. i know how to create a file with c++ using
but is there a way to save it to a specific location on your computer with windows and linux if you could please
You can specify a full path when you create a file, eg in Linux
Code:

myfile.open("/home/xsky/newfile.txt");
(see the MSDN for full path naming in a Windows environment)

Or you can chdir to change the current working directory so that files that are created will be in the new working directory, rather than the one where the executable starts. (SetCurrentDirectory in Windows)

Quote:

2. i need to know how to run/execute/open a file in a c++ program
im using and its not working
I'm not quite sure if you just mean to run another executable from within a C++ program? You can use the system call if that is what you mean. (CreateProcess in Windows)

pixellany 01-18-2010 02:51 PM

Please post your thread in only one forum. Posting a single thread in the most relevant forum will make it easier for members to help you and will keep the discussion in one place. This thread is being closed because it is a duplicate.


All times are GMT -5. The time now is 10:14 AM.