C++ comment remover

Remove comments from
C++ code.

Strip comments from C++ source code online. Handles raw string literals, namespace declarations, templates, and every comment style you'd find in modern C++.

Free, no signup Runs in your browser Instant, no upload Works on .cpp files

Before and after

Real-world C++ code on the left. The same code with every comment removed on the right.

c++-input.cpp
// matrix.cpp - small dense matrix utilities
#include <vector>
#include <algorithm>

namespace mx {

/**
 * Row-major dense matrix of doubles.
 */
template <typename T>
class Matrix {
public:
    Matrix(size_t rows, size_t cols) // construct empty
        : rows_(rows), cols_(cols), data_(rows * cols) {}

    /* Element access. */
    T& at(size_t r, size_t c) {
        return data_[r * cols_ + c]; // row-major
    }

    auto raw_query() const {
        return std::string(R"(SELECT * FROM x WHERE y = "//")"); // not a comment
    }

private:
    size_t rows_, cols_;        // dimensions
    std::vector<T> data_;       // backing store
};

}  // namespace mx
c++-output.cppcleaned
#include <vector>
#include <algorithm>

namespace mx {

template <typename T>
class Matrix {
public:
    Matrix(size_t rows, size_t cols)
        : rows_(rows), cols_(cols), data_(rows * cols) {}

    T& at(size_t r, size_t c) {
        return data_[r * cols_ + c];
    }

    auto raw_query() const {
        return std::string(R"(SELECT * FROM x WHERE y = "//")");
    }

private:
    size_t rows_, cols_;
    std::vector<T> data_;
};

}
Why use it

Built for C++ specifically.

C++ files are dense, and the comments that decorate templates, operator overloads, and macro-heavy code can dominate the byte count. Removing them is also the first step many developers take when posting a minimal reproducible example to Stack Overflow or to a compiler-explorer-style sandbox. Uncommenter correctly handles raw string literals like R"(...)", a feature missed by most regex-based strippers.

  • // and /* */ comments removed
  • Raw string literals R"(content)" preserved including embedded quotes
  • Templates, namespaces, and operator overloads untouched
  • Doxygen-style /** */ blocks treated as regular block comments
  • Auto-detected from .cpp, .cc, .cxx, .hpp, .hh, .hxx files
How it works

Strip comments in 30 seconds.

  1. 1

    Open the tool

    Head to uncommenter.com/tool. Nothing to install. Nothing to sign up for.

  2. 2

    Paste your C++ code

    Drop your .cpp file in, or paste code into the editor. Auto-detection picks up C++ from the extension or file content.

  3. 3

    Click 'Remove Comments'

    The parser walks every character with a real state machine, strings, regex, and other context-sensitive parts are detected and left alone.

  4. 4

    Copy or download

    Grab the cleaned output. Your code never left your browser.

FAQ

C++ questions, answered.

Does it support raw string literals?

+

Yes. R"(...)" and the d-char-sequence variant R"delim(...)delim" are recognized as raw strings, so any // or /* inside them is preserved verbatim.

Will it remove license headers?

+

License headers are usually block comments at the top of the file, so yes, they're removed along with everything else. If you want to preserve them, the easiest path is to add the license back in via a build step after running Uncommenter.

What about preprocessor macros?

+

Macros and includes are language syntax, not comments. They're always preserved.

Other languages

Working in something else?

Plus 35+ more languages supported in the live tool , including HTML, YAML, Dockerfile, Terraform, Solidity, and more.

Try it on your C++ code now.

Free forever. No signup. No upload. Runs entirely in your browser.

Open uncommenter