简体   繁体   English

C ++ ostream引用

[英]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? 为什么下面的第4行打印一个内存地址,而不是第2行打印的原始字符串,我该如何纠正呢? Many thanks. 非常感谢。

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

Use the str() function to get the underlying string: 使用str()函数获取基础字符串:

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

For future reference here's a reference on std::stringstream , which contains every member function. 为了将来参考,这里是std::stringstream 的参考 ,其中包含每个成员函数。

删除&运算符

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM