Go Back   The PokéCommunity Forums > Creative Discussions > Game Development

Notices
For all updates, view the main page.

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



Closed Thread
Click here to go to the first staff post in this thread.  
Thread Tools
  #1    
Old March 16th, 2014 (08:50 PM). Edited March 16th, 2014 by Kakarot1212.
Kakarot1212's Avatar
Kakarot1212
Awesome as always...
 
Join Date: Oct 2013
Location: Phillipines
Age: 17
Gender: Male
Nature: Naughty
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
__________________

楓 弘詩
“ Programs must be written for people
to read, and only incidentally for
machines to execute. ”

Pair | Pair| Facebook | Showdown | PHO | Twitter
| Text Hex Convert v2.1.1 |
  #2    
Old March 17th, 2014 (04:42 AM).
th3shark's Avatar
th3shark
Develops in AS3/C++
 
Join Date: Jul 2013
Location: Connecticut
Gender: Male
Nature: Calm
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 (05:34 AM).
Maruno's Avatar
Maruno
Lead Dev of Pokémon Essentials
 
Join Date: Jan 2008
Location: England
...Not really about a game, is it? Nor did you mention which language your little project was in, which is unhelpful.

Thread closed.
__________________
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
Minimum Characters Per Post: 25



All times are UTC -8. The time now is 04:14 AM.