---
title: "ostringstream 的清空数据方法"
author: "qimo601"
date: "2012-09-27T15:28:57Z"
tags: []
categories: ["编程语言"]
slug: "ostringstream"
draft: false
lastmod: "2012-09-27T15:28:57Z"
id: 1687403
url: "https://qimo601.iteye.com/blog/1687403"
---

关于C++中 &lt;sstream&gt;中ostringstream的清空方法。

 

```
ostringstream outString;
outString.str("");//清空数据
```

 

   容易混淆的是，outString.clear()//清空错误的标志位

 

   outString.str()有种两种用法，Get/set the associated string object (public member function)

 

 1、string str ( ) const;//获取当前字符串

 2、void str ( const string & s );//设置当前数据流为该字符串s

 

The first version returns a copy of the string object currently associated with the string stream buffer.

The second syntax copies the content of string s to the string object associated with the string stream buffer. The function effectivelly calls rdbuf()-&gt;str().