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
  #1    
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: 548
    I think this is the best place to post this.

    AND I NEED THIS TO BE ANSWERED QUICK!

    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.
    http://pastebin.com/6pm1a5NA
    __________________

    Relevant Advertising!

      #2    
    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:
      Code:
      ofstream myfile;
      myfile.open ("fileName.txt");
      myfile << title << " " << bookNumber << " " << author << '\n';
      myfile.close();
      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:
      Code:
      ofstream myFile;
      myFile.open("fileName.txt", ofstream::out | ofstream::trunc);
      myFile.close();
      3. Deleting a file:
      Code:
      #include <stdio.h>
      
      if( remove( "myfile.txt" ) != 0 )
          cerr << "Error deleting file" << endl;
      else
          cout << "File successfully deleted" << endl;
      __________________
        #3    
      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,173
        ...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

        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 8:06 AM.