This class allows me to quote strings being sent to an output stream:
class Quote{
public:
friend std::ostream& operator<<(std::ostream& os, const Quote& obj){
obj.write(os);
return os;
}
Quote() = delete;
Quote(const string & text): text(text){}
void write(ostream & os) const{
os << default_quote_token << text << default_quote_token;
}
private:
const string & text;
};
Like this:
os << Quote(name);
It feels like a lot of work to avoid:
os << "\"" << name << "\"";
Is there a better solution?