Thread: writing/reading txt file

  1. #1
    Sir Mister Insane Sako Klinerr1's Avatar
    Join Date
    May 2002

    writing/reading txt file

    this would be used alot in console rpgs that let you save your stats. i want to be able to write to a txt file a bunch of my variables and then be able to read the txt file and making variables so its a save/load type thing. i searched google and the forums couldnt find anything. any help thanks in advance
    Email: || AIM: MisterSako || MSN:

    -the shroom has spoken

  2. #2
    Registered User major_small's Avatar
    Join Date
    May 2003
    read the FAQ
    Join is in our Unofficial Cprog IRC channel
    Channel: #Tech

    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  3. #3
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    #include <iostream>
    #include <fstream>
    #include <string>
    using namespace std;
    void save(int i, double d, const string &str)
        ofstream fout("save.txt"); // no error checking
        fout << i << endl
             << d << endl
             << str << endl;
    void load(int &i, double &d, string &str)
        ifstream fin("save.txt"); // no error checking
        fin >> i >> d;
        fin.ignore(1); // skip newline
        getline(fin ,str);
    int main()
        int i = 42;
        double d = 3.1415926535897932384626433832795;
        string str = "life is like a piece a pie";
        save(i, d, str);
        i = 0;
        d = 0;
        str = "";
        load(i, d, str);
        cout << i << endl << d << endl << str << endl;
        return 0;

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  2. Batch file programming
    By year2038bug in forum Tech Board
    Replies: 10
    Last Post: 09-05-2005, 03:30 PM
  3. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  4. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 10:12 PM
  5. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 04:10 PM