Thread: File I/O

  1. #1
    Unregistered
    Guest

    Question File I/O

    Hello,

    I am trying to write a small(?) program that does the following:

    1. Opens a file with a hardcoded filename (read)
    2. Opens a file with a hardcoded filename (write)
    2. Read the file line by line (read), and outputing each line into a new file (write).

    Basically taking a text file and turning it into an html page.

    Now I have some basic knowledge on writing to a file with ofstream, but I would just like a little more direction. If possible could you tell me which specific things I need to look up on the web or in a book, and some things to look out for.

    Currently I own the C++ in 21 days, and C in 24 hours.

    Thanks, and btw -- this isn't homework :)

  2. #2
    Unregistered
    Guest
    Everything you need to know in order to do this is in the chapter on streams in the C++ book. Here's some uncompiled code to look at. Look at each of the involved concepts in the book however to be sure you understand what is going on.

    char filename[30] = "oldfile.txt";
    char filename2[30] = "newfile.txt";

    ifstream fin(filename);
    ofstream fout(filenam2);

    char dummy[256];

    fin.getline(dummy, 255, '\n');
    while(fin)
    {
    fout << dummy;
    fout << '\n';
    fin.getline(dummy, 255, '\n');
    }

    fout.close();
    fin.close();

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Data Structure Eror
    By prominababy in forum C Programming
    Replies: 3
    Last Post: 01-06-2009, 09:35 AM
  2. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  3. 2 questions surrounding an I/O file
    By Guti14 in forum C Programming
    Replies: 2
    Last Post: 08-30-2004, 11:21 PM
  4. File I/O problems!!! Help!!!
    By Unregistered in forum C Programming
    Replies: 4
    Last Post: 05-17-2002, 08:09 PM
  5. advice on file i/o
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 11-29-2001, 05:56 AM