I have some c++ code with `/* */` and `//` style comments. I want to have a way to remove them all automatically. Apparently, using an editor (e.g. ultraedit) with some regexp searching for `/*`, `*/` and `//` should do the job. But, on a closer look, a complete solution isn't that simple because the sequences /\* or // may not represent a comment if they're inside another comment, string literal or character literal. e.g.

```
printf(" \" \" " "  /* this is not a comment and is surrounded by an unknown number of double-quotes */");

```

is a comment sequence inside a double quote. And, it isn't a simple task to determine if a string is inside a pair of valid double-quotes. While this

```
// this is a single line comment /* <--- this does not start a comment block 
// this is a second comment line with an */ within

```

is comment sequences inside other comments.

Is there a more comprehensive way to remove comments from a C++ source taking into account string literal and comment? For example can we instruct the preprocessor to remove comments while doesn't carry out, say, #include directive?