The PokéCommunity Forums Fan Games Game Development
Question Coding Help!

Game Development Your number one stop for anything related to creating games (except ROM hacks). You can even make your own!

Closed Thread
Thread Tools
Old March 16th, 2014 (8:50 PM). Edited March 16th, 2014 by Kakarot1212.
Kakarot1212's Avatar
Kakarot1212 Kakarot1212 is offline
Resident Programmer
    Join Date: Oct 2013
    Location: Phillipines
    Gender: Male
    Nature: Adamant
    Posts: 553
    I think this is the best place to post this.


    So i'm working on a project, simple library system. I just don't know how to do this one thing.

    Example, the user will input the following datas: title, book number and author.
    My question is, 1) how do I output it to a .txt file 2) how can I edit that txt file afterwards and 3) how can I delete the txt file. I know it is through fstream, but i don't know how to do it.
    Give some sample code if possible. Help is appreciated!

    Edit: Here's the code of my Library system if you need.

    Relevant Advertising!

    Old March 17th, 2014 (4:42 AM).
    th3shark's Avatar
    th3shark th3shark is offline
    Develops in AS3/C++
      Join Date: Jul 2013
      Location: Connecticut
      Gender: Male
      Nature: Calm
      Posts: 79
      Well I did some Google searching for you and this is what I found:

      1. Writing to a text file:
      ofstream myfile; ("fileName.txt");
      myfile << title << " " << bookNumber << " " << author << '\n';
      2. Editing a text file is trickier than programs like Notepad would have you believe. I recommend getting all the data from a text file, storing it somewhere, then clear the text file and write to it again. It appears writing with the truncate option will delete the content:
      ofstream myFile;"fileName.txt", ofstream::out | ofstream::trunc);
      3. Deleting a file:
      #include <stdio.h>
      if( remove( "myfile.txt" ) != 0 )
          cerr << "Error deleting file" << endl;
          cout << "File successfully deleted" << endl;
      Old March 17th, 2014 (5:34 AM).
      Maruno's Avatar
      Maruno Maruno is offline
      Lead Dev of Pokémon Essentials
        Join Date: Jan 2008
        Location: England
        Posts: 5,189
        ...Not really about a game, is it? Nor did you mention which language your little project was in, which is unhelpful.

        Thread closed.
        Go to the Pokémon Essentials Wiki

        | Downloads | Tutorials | Fangames |
        | All Animations Project |

        Follow me on Twitter: @maruno42

        Closed Thread

        Quick Reply

        Join the conversation!

        Create an account to post a reply in this thread, participate in other discussions, and more!

        Create a PokéCommunity Account

        Sponsored Links
        Thread Tools

        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 On
        HTML code is Off

        Forum Jump

        All times are GMT -8. The time now is 9:05 PM.