LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-15-2010, 09:49 PM   #1
xskycamefalling
Member
 
Registered: May 2009
Posts: 43

Rep: Reputation: 15
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.
 
Old 01-16-2010, 12:24 AM   #2
neonsignal
Senior Member
 
Registered: Jan 2005
Location: Melbourne, Australia
Distribution: Debian Bookworm (Fluxbox WM)
Posts: 1,391
Blog Entries: 54

Rep: Reputation: 360Reputation: 360Reputation: 360Reputation: 360
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)

Last edited by neonsignal; 01-16-2010 at 12:44 AM.
 
Old 01-18-2010, 02:51 PM   #3
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help Trying to open or run a file/program through a c++ program xskycamefalling Programming 4 01-19-2010 02:26 PM
open source dvd/cd copy program? burning on the fly program? vieya Linux - Software 3 12-14-2009 09:16 PM
Simple C++ Program: Program Compiles But Won't Run (Segmentation Fault) violagirl23 Programming 3 01-09-2008 12:09 AM
Open a Terminal and run a program after Gnome boot. sirius56 Linux - Newbie 8 01-02-2007 07:39 PM
Viewing program messages when program isn't run from command line? Locura Linux - Software 1 09-27-2003 08:19 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:18 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration