Results 1 to 13 of 13

Thread: [Resolved] File Writing Help

  1. #1

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256

    [Resolved] File Writing Help

    I have this function:

    Code:
    void addmovie() {
        char string[50] = {'\0'};
    
        ofstream outFile("C:\\test.txt", ios::out);
        if (!outFile) {
            cout << "File could not be opened!" << endl;
            exit(0);
        }
    
        cout << "String: ";
        cin.ignore();
        cin.getline(string, 50, '\n');
    
        //outFile.seekp(outFile.eof());
        outFile << string;
        outFile << '\n';
    }
    How can I make it output at the end of the file, rather than overwriting it?

    I thought about reading the file, and adding to it, then writing it back...but is there any other way?
    Last edited by The Hobo; Feb 3rd, 2003 at 11:59 AM.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  2. #2
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    Code:
    ofstream outFile("C:\\test.txt", ios:ut);
    Instead of ios::out, try ios::app

    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  3. #3
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    I would suggest doing this:
    Code:
    string s;
    getline(cin, s);
    It's safer than your 50 character limit.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  4. #4

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by parksie
    I would suggest doing this:
    Code:
    string s;
    getline(cin, s);
    It's safer than your 50 character limit.
    I would love to, however my teacher will not allow it.

    crptcblade, I'll give it a try.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  5. #5

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by crptcblade
    Instead of ios::out, try ios::app

    That works great. Thanks
    My evil laugh has a squeak in it.

    kristopherwilson.com

  6. #6
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Originally posted by The Hobo
    I would love to, however my teacher will not allow it.

    crptcblade, I'll give it a try.
    ******* *****. I don't care what they think. Limited character arrays in a C++ program have NO PLACE WHATSOEVER. Trust me, I have been bitten on this. If your teacher has a problem, then they can come on here, and argue with those of us that have to put up with the problems caused by the ******* shoddily coded software that ends up being put out these days.


    ******s. They put their "qualifications" above common sense, and well known effects.



    (note: rant is aimed at teachers, not you)
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  7. #7

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by parksie
    ******* *****. I don't care what they think. Limited character arrays in a C++ program have NO PLACE WHATSOEVER. Trust me, I have been bitten on this. If your teacher has a problem, then they can come on here, and argue with those of us that have to put up with the problems caused by the ******* shoddily coded software that ends up being put out these days.


    ******s. They put their "qualifications" above common sense, and well known effects.



    (note: rant is aimed at teachers, not you) [/B]
    I agree with you, Mike. I really do. But right now all I care about is getting a grade I deserve, and stirring up controversy isn't going to get me that.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  8. #8
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Well. You have a choice.

    1. A qualification.

    2. Knowing that you are actually capable of doing something, and thinking for yourself.


    Oh, FYI, I have no qualifications concerning programming whatsoever.


    PS: I actually would quite like to speak to your teacher/instructor, if you can get them to PM me on here it would be greatly appreciated
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  9. #9
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    And when there are buffer overflow security bugs in an app people complain
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  10. #10

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by CornedBee
    And when there are buffer overflow security bugs in an app people complain
    Go whine somewhere else. There's nothing I can do about it.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  11. #11
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    There is, it just takes guts.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  12. #12
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Exactly. Use the string class and tell your teacher to **** off. Or maybe explain to him in reasonable words that there is absolutly no reason not to use the string class and that it has many advantages in many ways.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  13. #13

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by CornedBee
    Exactly. Use the string class and tell your teacher to **** off.
    My evil laugh has a squeak in it.

    kristopherwilson.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width