c/c++:字符串输入输出流

字符串输入输出流,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;

}

你可能感兴趣的:(c/c++)