回复 10楼 Jonny0201
不把os绑定到输出流上,只把array中的数组输入到os中,然后在另外写个函数os中读取数据。还有一个小问题,
Foo(ostream &os) : os {os} {}
中的os{os}和os(os)的区别是什么呢?




2019-01-03 23:14
程序代码:#include <iostream>
#include <sstream>
using namespace std;
int main( void )
{
std::ostringstream os;
os << 123 << "abc";
cout << os.str() << endl;
}
2019-01-04 08:20
2019-01-04 10:46
2019-01-04 12:09
2019-01-04 12:47
程序代码:#include <iostream>
#include <sstream>
using namespace std;
int main( void )
{
istringstream is( "123" );
string s;
is >> s;
cout << s << endl;
}输出 123
程序代码:#include <iostream>
#include <sstream>
using namespace std;
int main( void )
{
ostringstream os;
os << "123";
cout << os.str() << endl;
}
2019-01-04 14:27
2019-01-04 15:32
2019-01-07 18:27


2019-01-07 20:18