I have an object that returns a non const string reference. I'd like to pass this string reference to a method that takes a reference to an ostream, allowing that method to write to the string reference. Is there way to wrap a string reference in an ostream (using std or boost libraries) such that the string reference can be written to via an ostream?I do not want to use stringstream since that copies the string, thus not writing to the original.
For example.
void write_to_it(std::ostream& os) {
os << "cat";
}
int main() {
std::string a;
std::string& b(a);
std::ostream os(b);
write_to_it(os);
return 0;
}
Aucun commentaire:
Enregistrer un commentaire