I am trying to create a program that takes a text file of C ++ code and displays another file with this code, minus any comments it contains.
Assuming rFile and wFile are defined as follows:
ifstream rFile; // File stream object for read only
ofstream wFile; // File stream object for write only
rFile.open("input.txt", ios::in);
wFile.open("output.txt", ios::out);
My first thought was to just go through the text and do the equivalent of pen-up (logo link) when (slightly improved) peek () identifies / * and writes the pen when it sees * /. Of course, after seeing // it will be a "pen-up" until it reaches \ n.
The problem with this approach is that output.txt does not include any of the source spaces or newlines.
This was the code (I didn’t even try to delete the comments at this stage):
while (!rFile.eof())
{
rFile>>first; //first is a char
wFile<<first;
}
, getline(),
endl wFile. , ,
.
, , - - . ( !)
N.B. , ,
++, C.