#include <iostream> #include <string> #include <memory> using namespace std; typedef unsigned char byte; class styledChar { public: styledChar() {}; styledChar(wchar_t chr): _chr(chr), _styleIndex(0) {}; wchar_t GetChar() const { return _chr; }; byte GetStyleIndex() const { return _styleIndex; }; void SetStyleIndex(byte styleIndex) { _styleIndex = styleIndex; }; private: wchar_t _chr; byte _styleIndex; }; class styledString: public basic_string<styledChar> { public: styledString(const wstring& right) : basic_string<styledChar>(CreateBuf(right).get(), right.length()) { } private: static unique_ptr<styledChar[]> CreateBuf(const wstring& right) { unique_ptr<styledChar[]> buf(new styledChar[right.length()]); int i = 0; for (auto r : right) { styledChar ch(r); buf[i++] = ch; } return buf; } friend wostream& operator<< (wostream &out, const styledString &str) { for(auto c : str) { out << c.GetChar(); } return out; }; }; int main() { styledString s(L"test string"); wcout << s << endl; return 0; }
We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy. Accept Learn more