hi, this code below lets me insert a .cpp file and removes any comments start with /* and end with */ so i edited it so that it removes comments start with // .
but there is a problem in it : when it find // it starts removing and can't stop .
i want to tell the code when you find a new line or whatever, stop removing. how can i do this ?
Why do you want to remove comments? The pre-processor does this for you before compiling the program. Besides, comments are an invaluable documentation feature.
I don't know why you are using boolean to decide whether or not the program is "inside of a comment". I've posted an example I just coded up to give you an idea on how you could solve this challenge. If you want me to fix your code, then you need to format your code and put the code between code tags.
I've tested the code provided and it works flawlessly. I've tested the code below with your program and it removes all of them. Is that not what you want? There are many ways you could improve your code.
1 2 3 4
#include /* string */ <string>
int main() { } // remove me
// now remove me
lines that end with a backslash continue on the next line:
1 2 3 4
// this is a single line comment, but it ends with an escape char: \
this line is also considered part of the comment \
as is this one (even if the forum syntax highlighting doesn't show it)
this_is_not_a_comment();