-
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 :)
-
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();