Write a program named h33.cpp that removes C++ comments from input, sending the uncommented portion of the program to output. Your program should work with both single line (//) comments, and multi-line (/* */) comments.
Remember:
A "/*" sequence is ended by the first "*/" that is encountered.
Comment characters inside string literals "don't count"
Strings quotes may be escaped using an escape character.
Single-line comments // may be included inside multi-line comments
Test your program against several different C++ files with different types of comments.
You'll find an example test file (test.cpp) that you can process. Use redirection to open the file and write to standard output. (That is, use cin and cout, not the filestream classes.) Check the output to see that only comments have been removed.
I kind of get what my professor is asking me. I think I would need to remove those comment line from a sentence.
// Single line comment should be deleted
/* Multi-line comment should be deleted
// Not really a comment
"Not really a string"
*****/
#include <iostream> // Single line comment should be deleted
using namespace std;
char * s = "Some text /* with an embedded */ // comment ";
int main(int argc, /* argument count */ char *argv[] /* strings */)
{
cout << s << endl;
cout << "/* this is ok " << endl;
cout << "as is this */" << endl;
}
This is the code to test, so the output would be /* this is ok, but I would need to remove that comment so it should come out to be "this is ok." Any help would be much appreciate. I just want someone to guide me.

New Topic/Question
Reply




MultiQuote








|