1 ostringstream oss;
 2 string city("ZhuHai");
 3 string name("Robot");
 4 string phoneNumber("10086");
 5 
 6 oss << city << " ";
 7 cout << oss.str() << endl;  // 输出ZhuHai
 8 oss << name << " ";
 9 cout << oss.str() << endl;  // 输出ZhuHai Robot,看到的现象是上一次写入ostringstream对象的值依然存在
10
11 12 oss.str(""); // 清空ostringstream对象中的内容 13 oss << phoneNumber<< " "; 14 cout << oss.str() << endl; // 输出10086

 

相关文章:

  • 2021-12-27
  • 2022-12-23
  • 2022-12-23
  • 2021-06-17
  • 2022-12-23
  • 2021-07-12
  • 2022-12-23
猜你喜欢
  • 2022-01-02
  • 2021-11-06
  • 2021-05-22
  • 2022-12-23
  • 2021-09-26
  • 2022-12-23
  • 2021-12-19
相关资源
相似解决方案