In: Computer Science
C++ program to read line comments.
This assignment will give you a little bit of practice with string parsing.
Your task is to write a program that reads in a .cpp file line-by-line, and prints out only the text that's after the // characters that indicate a single-line comment.
You do not have to worry about
/*
multiline comments
*/
though there will be a small amount of extra credit for programs that correctly extract these comments as well.
PLEASE GIVE IT A THUMBS UP, I SERIOUSLY NEED ONE, IF YOU NEED ANY MODIFICATION THEN LET ME KNOW, I WILL DO IT FOR YOU
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
fstream newfile;
newfile.open("DynamicQueue.h", ios::in);
if (newfile.is_open())
{
string tp;
while (getline(newfile, tp))
{
int i = 0;
for (i = 0; i < tp.size(); i++)
{
if ((i + 1) < tp.size())
if (tp[i] == '/' && tp[i + 1] == '/')
break;
}
i += 2;
int flag = 0;
while (i < tp.size())
{
cout << tp[i];
i += 1;
flag = 1;
}
if (flag == 1)
cout << endl;
}
newfile.close();
}
}