Hi, my member function write() get called with string arguments like: Hello \n World \n Traceback ...\n NameError : name ... not defined \n etc. I want to add a prefix (a prompt '>>>' concete) so that the result will become:
Hello World Traceback .... NameError: name ... not defined
Yes, this comes from redirected python output. The simplest solution seems to use regex/xpressive: class redirector { const std::string m_prompt; const xpr::sregex m_re; const std::string m_re_fmt; public: redirector(const std::string& prompt = ">>> ") : m_prompt(prompt), m_re(xpr::sregex::compile("(\\n)!")), m_re_fmt(m_prompt + "\n") { } void write(const std::string& text) { std::cout << m_prompt << xpr::regex_replace(text, m_re, m_re_fmt); } ... }; where my regex won't work. What is the correct one since I can get a single '\n', a terminated '\n' or multiline strings separated by '\n'. Is this approach good for this problem? Anyway, I get a lot of warnings from constructor and write function, any ideas why? Thanks, Olaf