How to open a file in c++

Discussion in 'C++' started by sam, Sep 11, 2008.

  1. sam

    sam Guest

    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
     
    sam, Sep 11, 2008
    #1
    1. Advertising

  2. sam

    Guest

    On 11 Sep, 13:47, sam <> wrote:
    > 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
     
    , Sep 11, 2008
    #2
    1. Advertising

  3. Pascal J. Bourguignon, Sep 11, 2008
    #3
  4. Pete Becker <> writes:

    > On 2008-09-11 10:17:45 -0400, (Pascal
    > J. Bourguignon) said:
    >
    >> sam <> writes:
    >>> I just wanted to know how will open a file in c++(Any exe file or
    >>> any other type file)

    >> Using the stl::fstream::eek:pen method.
    >> http://www.cplusplus.com/reference/iostream/fstream/open.html
    >>
    >>> and if i wanted to run that exe , How will i ?

    >> AFAIK, there's nothing in the stl to do that, but this can be done
    >> using the POSIX system function.
    >> http://www.opengroup.org/onlinepubs/009695399/functions/system.html

    >
    > 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?


    ;-)
    --
    __Pascal Bourguignon__
     
    Pascal J. Bourguignon, Sep 11, 2008
    #4
  5. sam

    James Kanze Guest

    On Sep 11, 5:42 pm, (Pascal J. Bourguignon)
    wrote:
    > Pete Becker <> writes:
    > > On 2008-09-11 10:17:45 -0400, (Pascal
    > > J. Bourguignon) said:


    > >> sam <> writes:
    > >>> I just wanted to know how will open a file in c++(Any exe file or
    > >>> any other type file)
    > >> Using the stl::fstream::eek:pen method.
    > >>http://www.cplusplus.com/reference/iostream/fstream/open.html


    > >>> and if i wanted to run that exe , How will i ?
    > >> AFAIK, there's nothing in the stl to do that, but this can be done
    > >> using the POSIX system function.
    > >>http://www.opengroup.org/onlinepubs/009695399/functions/system.html


    > > 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?


    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.

    --
    James Kanze (GABI Software) email:
    Conseils en informatique orientée objet/
    Beratung in objektorientierter Datenverarbeitung
    9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
     
    James Kanze, Sep 11, 2008
    #5
  6. sam

    arnuld Guest

    > On Thu, 11 Sep 2008 10:39:05 -0400, Pete Becker wrote:

    > 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 ?



    --
    www.lispmachine.wordpress.com
    my email is @ the above blog.
    Google Groups is Blocked. Reason: Excessive Spamming
     
    arnuld, Sep 12, 2008
    #6
  7. arnuld a écrit :
    >> On Thu, 11 Sep 2008 10:39:05 -0400, Pete Becker wrote:

    >
    >> 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 ?


    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 :)

    --
    Michael
     
    Michael DOUBEZ, Sep 12, 2008
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. THY
    Replies:
    4
    Views:
    534
    Gönen EREN
    Aug 22, 2003
  2. ml
    Replies:
    0
    Views:
    1,493
  3. ml
    Replies:
    2
    Views:
    4,900
    John C. Bollinger
    Nov 30, 2004
  4. Corne' Cornelius

    multiple open fd's on open(file)

    Corne' Cornelius, Aug 22, 2003, in forum: C Programming
    Replies:
    2
    Views:
    452
    -berlin.de
    Aug 22, 2003
  5. Schüle Daniel

    File::open and File.open

    Schüle Daniel, Oct 23, 2006, in forum: Ruby
    Replies:
    4
    Views:
    213
    Rick DeNatale
    Oct 24, 2006
Loading...

Share This Page