How to open a file in c++

S

sam

Sir,

I just wanted to know how will open a file in c++(Any exe file or
any other type file) and if i wanted to run that exe , How will i ?
Please provide me little idea and code of this program.

Thanks in advance
 
N

newbarker

Sir,

 I just wanted to know how will open a file in c++(Any exe file or
any other type file) and if i wanted to run that exe , How will i ?
Please provide me little idea and code of this program.

                                        Thanks in advance

Lookup the function called system(). Here's an untested example:

#include <process.h>

int main()
{
system("fred.exe");
}

Regards,

Pete
 
P

Pascal J. Bourguignon

Pete Becker said:
Even better, use the standard C and standard C++ function
system(). Available through <stdlib.h> or, for purists, <cstdlib>.

What would be really the best? Using the standard C or C++ system
function, or using the POSIX standard system function?

I think I'd prefer to stick to the POSIX standard. Why would you
prefer the C standard?


;-)
 
J

James Kanze

What would be really the best? Using the standard C or C++
system function, or using the POSIX standard system function?

Well, the Posix standard for "system" starts by saying "The
functionality described on this reference page is aligned with
the ISO C standard. Any conflict between the requirements
described here and the ISO C standard is unintentional. This
volume of IEEE Std 1003.1-2001 defers to the ISO C standard."
So the C standard is the "original source".
I think I'd prefer to stick to the POSIX standard. Why would
you prefer the C standard?

In the context of this group, we prefer the C++ standard. Now
if the question had been asked in comp.unix.programming, we'd
prefer the Posix standard. Both, however, defer to the C
standard.
 
A

arnuld

Even better, use the standard C and standard C++ function system().
Available through <stdlib.h> or, for purists, <cstdlib>.


I think std::fstream::eek:pen is much better than using system() . What other
people say ?
 
M

Michael DOUBEZ

arnuld a écrit :
I think std::fstream::eek:pen is much better than using system() . What other
people say ?

The two functions are unrelated: fstream reads the content of the file
while system executes a command.

There is no matter of preference here, just a poor wording from the OP
and multiple answer depending on what people read :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top