Hello all, this is my first post here. I have been enrolled in a C++ class for about 3 weeks, and found this site after my first class and have been reading the references and source code very frequently. We received our first assignment which was to write a comment stripper in Visual Studio 2008.
The guidelines of the project were to remove // comments, /*...*/ comments, and ignore // or /*...*/ if inside of a string.
As of right now, my code is removing comments from inside a string. I'm just inputting the code of program itself, and writing out to a text file. What is outputting is...
1 2
|
string example;
example = "text
|
When what I need it to output is
1 2
|
string example;
example = "text//text";
|
For the other two conditions, I used .peek and .get. So, summed up, if input.get == '/' then, depending on what the next character was, either a / or a *, it would do its thing.
The issue I can't seem to comprehend is getting the program to 'see' a set of quotation marks, and output the line until it hits the closing quotation marks, ignoring everything in between.
I looked at functions here and what I've discovered is string::find, and string::find_last_of. But the quotation marks will always be at the end of the line, ignoring carriage return.
I guess what I'm asking is if someone can point my thinking to something relevant. What I have so far(and please don't laugh, I'm sensitive;) ) is for checking the quotation marks, however it is just deleting everything after the // in a string as per above example.
1 2 3 4 5 6 7
|
while (charCurrent == '"'){
charNext = input.peek();
getline(input, str);
if(charNext != '"'){
getline(input, str);
}
}
|
Any guidance that can be given would be greatly appreciated, and I apologize in advance for writing the above novel.
Thanks in advance:)