Help with this!

This is a discussion on Help with this! within the C++ Programming forums, part of the General Programming Boards category; hello,can someone shows me how to get open file function,close,print and save functions?i need it so urgent.thax!!...

  1. #1
    Ferraski
    Guest

    Help with this!

    hello,can someone shows me how to get open file function,close,print and save functions?i need it so urgent.thax!!

  2. #2
    Registered User programmer's Avatar
    Join Date
    Oct 2001
    Posts
    22
    Not sure if this is what your after, but in its most basic form, i'd do it like this:

    #include <fstream.h>

    main()
    {
    char ch;
    char filename[20] = "c:test.txt";
    int mode = ios:ut;
    fstream fout(filename, mode );
    cout << "Ready for input, use CTRL+Z to end" << endl;
    while ( cin.get( ch ) )
    {
    fout.put( ch );
    }
    fout.close();
    return(0);
    }

    fout.close(); is important, miss it and you could **** up your whole hd.

    to open the file:

    #include <fstream.h>

    main()
    {
    char ch;
    char filename[20] = "c:test.txt";
    int mode = ios::in;

    fstream fin(filename, mode );
    if (!fin)
    cout << "Unable to open file";
    while ( fin.get(ch) )
    {
    cout << ch;
    }
    fin.close();
    return(0);
    }

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    53
    Do you mean with dialog boxes Ferraski? As in Visual C++ or Borland Builder or something? Or do you mean the functional part of it, the actual opening, closing etc.?

    Didn't you use that post for another question programmer??

    Almosthere
    "Technology has merely provided us with a more efficient means for going backwards" - Aldous Huxley

  4. #4
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145

    hmm

    He uses that answer in all of his replies, eventually one of them answers the question

    No, I'm just kidding...
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  5. #5
    Ferraski
    Guest

    Unhappy HOW?

    yes,almost_here.
    well,it's some sort of mfc. it's like well,a clicking button like the toolbar there.when u clicked on open,it will open a new and when u clicked on close,it will close the file. it's same like the microsoft word. so,how should i do it? yeah i meant the functional part of it. how the code looks like for it?i am doing the vc++.it's like a dialog boxes. u r right...almost_here

  6. #6
    Registered User
    Join Date
    Nov 2001
    Posts
    53
    Ah. Then i'm afraid i can't help you, sorry. I don't use windows-dialog controls. I'm sure someone here does more visual app-based developing in VC++ than i do though... I stick to console apps mostly. If it's MFC you're after it's probably dead straightforward too - they're just standard dialogs.

    Sorry couldn't be more helpful - check out some VC tutorials and look up "dialog controls" with "save", "open","print". Although "print" is likely to be more difficult - depending on what you want to print.

    Actually, forget that last comment. MFC probably does that for you too.

    Ah.
    "Technology has merely provided us with a more efficient means for going backwards" - Aldous Huxley

  7. #7
    Registered User
    Join Date
    Nov 2001
    Posts
    21

    note to almost here and 'programmer'

    it was me who used that code, to reply to someone elses query a while back, im all for sharing the knowledge, but im also for creditting the original author. The code isnt even that good.

Popular pages Recent additions subscribe to a feed

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