K
kelvSYC
Suppose I have something like this:
class foo {
std::istream in;
public:
foo(std::istream& in_) : in(in_.rdbuf());
void doStuffWith(std:stream& out);
void bar();
};
where doStuffWith reads stuff from in and writes stuff to out.
Now, suppose bar() was like this:
void foo::bar() {
std:stringstream out;
doStuffWith(out);
in.rdbuf(out.rdbuf());
// read stuff from in
}
and a foo object was instantiated with an std::ifstream. At the end
of bar(), we would expect that you would effectively read the
characters that were put into out from doStuffWith(). Yet, I keep
reading from the (beginning of the) original filebuf instead. Why is
this going on, and how can I fix it so it does what I expect it to do?
class foo {
std::istream in;
public:
foo(std::istream& in_) : in(in_.rdbuf());
void doStuffWith(std:stream& out);
void bar();
};
where doStuffWith reads stuff from in and writes stuff to out.
Now, suppose bar() was like this:
void foo::bar() {
std:stringstream out;
doStuffWith(out);
in.rdbuf(out.rdbuf());
// read stuff from in
}
and a foo object was instantiated with an std::ifstream. At the end
of bar(), we would expect that you would effectively read the
characters that were put into out from doStuffWith(). Yet, I keep
reading from the (beginning of the) original filebuf instead. Why is
this going on, and how can I fix it so it does what I expect it to do?