字符串输入输出流,istringstream、ostringstream,可以将输入或输出变成一个string,多次读写或多次输出。
也可以通过这两个实现变量类型的转换,如int 型数据输出到ss(stringstream),然后读取到string 中。

 

#include <iostream>
#include <sstream>
#include <windows.h>

using namespace std;

int main()
{
    string buf;
    getline(cin,buf);/* 这个可以结合一下语句在处理文件读取时使用,先读整行,然后像cin处理   */
    istringstream is(buf);
    string temp;
    ostringstream os;
    while(is>>temp)
    {
        os<<temp<<" !!v"<<endl;
        system("pause");
    }
    temp=os.str();
    cout<<temp<<endl;

    return 0;
}

相关文章:

  • 2022-12-23
  • 2021-08-04
  • 2021-11-17
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-27
猜你喜欢
  • 2021-12-04
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-13
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案