C++ reduce repetitions of code for similar classes
Yes, there is. In fact, a very nice way to solve this code redundancy issue comes to mind if you consider that std::string is a just type alias for std::basic_string&lt;char&gt; and std::wstring an alias for std::basic_string&lt;wchar_t&gt;. Likewise, std::stringstream and std::wstringstream are also just aliases for std::basic_stringstream&lt;char&gt; and std::basic_stringstream&lt;wchar_t&gt;, respectively. This allows for an easy template-based approach to the problem.

What really suggests itself to me is keeping this alias-of-template-base-type pattern from the STL (although there may be other valid approaches as well), an implementation of which could look something like this:

#include &lt;sstream&gt;
#include &lt;string&gt;

namespace impl {

    template &lt;typename CharType&gt;
    class StringBuilderImpl {

        std::basic_stringstream&lt;CharType&gt; stream;

        public:
        template &lt;typename T&gt;
        StringBuilderImpl&amp; operator&lt;&lt;(T const&amp; t) {
            stream &lt;&lt; t;
            return *this;
        }

        operator std::basic_string&lt;CharType&gt;() const {
            return stream.str();
        }
    };
}

using StringBuilder = impl::StringBuilderImpl&lt;char&gt;;
using WStringBuilder = impl::StringBuilderImpl&lt;wchar_t&gt;;


StringBuilderImpl corresponds somewhat to std::basic_[string/stringstream] and takes the underlying character type as a template argument. Your former classes StringBuilder and WstringBuilder are now only aliases for certain template specializations, just as std::[string/wstring] and std::[stringstream/wstringstream] are.

(In my code, StringBuilderImpl is kind of hidden away inside an impl namespace. If it serves your need, however, you could also make it part of the public interface of your program library, allowing further specifications such as StringBuilderImpl&lt;char16_t&gt;)