How can I automatically replace all C style comments (/* comment */
) by C++ style comments (// comment
)?
This has to be done automatically in several files. Any solution is okay, as long as it works.
Single-line comments start with two forward slashes ( // ). Any text between // and the end of the line is ignored by the compiler (will not be executed).
Single-line comments (informally, C++ style), start with // and continue until the end of the line. If the last character in a comment line is a \ the comment will continue in the next line. Multi-line comments (informally, C style), start with /* and end with */ .
In C/C++ there are two types of comments :Single line comment. Multi-line comment.
You can comment out one or more lines of code in any C/C++ editor view. The leading characters // are added to the beginning of each line when commenting one or more lines of code. You can also block comment multiple lines of code using the characters /* */ .
This tool does the job: https://github.com/cenit/jburkardt/tree/master/recomment
RECOMMENT is a C++ program which converts C style comments to C++ style comments.
It also handles all the non-trivial cases mentioned by other people:
This code incorporates suggestions and coding provided on 28 April 2005 by Steven Martin of JDS Uniphase, Melbourne Florida. These suggestions allow the program to ignore the internal contents of strings, (which might otherwise seem to begin or end comments), to handle lines of code with trailing comments, and to handle comments with trailing bits of code.
This is not a trivial problem.
int * /* foo
/* this is not the beginning of a comment.
int * */ var = NULL;
What do you want to replace that with? Any real substitution requires sometimes splitting lines.
int * // foo
// this is not the beginning of a comment.
// int *
var = NULL;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With