C/C++ sstream

ostringstream
#include 
#include 
#include 
using namespace std;

int main()
{
    ostringstream ostr1;
    ostr1 << "123" << endl;//换行也加入
    cout << ostr1.str();
    long curPos = ostr1.tellp(); //返回当前插入的索引位置(即put pointer的值)
    cout << "curPos = " << curPos << endl;
    ostr1.seekp(4);     // 设置put pointer的值
    ostr1.put('g');     // 在put pointer的位置上写入'g',并将put pointer指向下一个字符位置
    cout << ostr1.str() << endl;
    ostr1.clear();
    string ss = ostr1.str();
    const char *buffer = ss.c_str();
    cout << buffer << endl;
    return 0;
}

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