पर विचार करें:अंतर << 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 is over-written by s_b
//
// Replacing line *** above with "ss_2 << ss_2.str() << " " << s_b;"
// results in ss_2 having the same content as ss_1.
सवाल:
क्या stringstream.str (a_value) के बीच का अंतर है, और स्ट्रिंगस्ट्रीम < < a_value; और, विशेष रूप से, पहले क्यों < < के माध्यम से concatenation की अनुमति देता है लेकिन दूसरा करता है?
क्यों ss_1 स्वचालित रूप से s_a और s_b के बीच सफेद स्थान प्राप्त किया था, लेकिन हम स्पष्ट रूप से लाइन है कि लाइन *** बदल सकते में सफेद स्थान जोड़ने की जरूरत है:ss_2 << ss_2.str() << " " << s_b;
?
आप में उदाहरण के लिए, आपके तार खाली हैं। S_a और s_b' के बीच स्वचालित रूप से 'व्हाइट-स्पेस' प्राप्त करने का क्या मतलब है? –
@JesseGood '// s_a और s_b में गैर-सफेद स्पेस शब्द ' –