Hello, so my assignment was to take a text file that contains a properly written C++ program code and to go through that code character by character and output all the comments in that code to another text file.
This is what I got so far, basically I`m wondering how to start copying characters right after "//" or "/*", at the moment it would output all the comments like this "// this is a comment", it would also output the '/' operator and anything after it until a new line, since char can only hold a single symbol. I also don`t need "//" or "/*" to appear in the output. Thanks in advance.
#include <iostream>
#include <fstream>
using namespace std;
int main ()
{
char c;
ifstream fin ("given.txt");
ofstream fout("comments.txt");
if (fout.is_open())
{
fin.get(c);
while (!fin.eof())
{
if (c == '/')
{
while (c != '\n')
{
fout.put(c);
fin.get(c);
}
fout << endl;
}
fin.get(c);
}
fout.close();
}
fin.close();
}