rize
rize

Reputation: 859

C++ ostream referencing

Why does line 4 in the following print a memory address instead of the original string printed by line 2, and how do I correct this? Many thanks.

std::stringstream os (std::stringstream::in | std::stringstream::out);
std::cout << result->studentId;
os << result->studentId;
std::cout << &os << std::endl;

Upvotes: 0

Views: 115

Answers (2)

Ravindra Bagale
Ravindra Bagale

Reputation: 17673

remove & operator

std::cout << os.str() << std::endl;

Upvotes: 0

Qaz
Qaz

Reputation: 61970

Use the str() function to get the underlying string:

std::cout << os.str() << std::endl;

For future reference here's a reference on std::stringstream, which contains every member function.

Upvotes: 3

Related Questions