相关疑难解决方法(0)

初始化stringstream.str(a_value)和stringstream << a_value之间的差异

考虑:

std::string        s_a, s_b;

std::stringstream  ss_1, ss_2;

// at this stage:
//     ss_1 and ss_2 have been used and are now in some strange state
//     s_a and s_b contain non-white space words

ss_1.str( std::string() );
ss_1.clear();

ss_1 << s_a;
ss_1 << s_b;

// ss_1.str().c_str() is now the concatenation of s_a and s_b, 
//                    <strike>with</strike> without space between them

ss_2.str( s_a );
ss_2.clear();

// ss_2.str().c_str() is now s_a

ss_2 << s_b;  // line ***

// ss_2.str().c_str() the value of s_a …
Run Code Online (Sandbox Code Playgroud)

c++ initialization concatenation stringstream

13
推荐指数
1
解决办法
2248
查看次数

标签 统计

c++ ×1

concatenation ×1

initialization ×1

stringstream ×1