2013-04-06 73 views
2

我有這樣的對象:如何將istringstream對象轉換爲字符串和字符數組?

istringstream ob_stream; 

我需要這個對象轉換爲字符串和字符數組工作。怎麼做?

+1

'ob_stream.str()'返回一個'的std :: string',並且可以調用返回的'std :: string'上的'c_str()' – 2013-04-06 22:17:32

+0

以及如何爲對象istream執行...示例istream is_object;我還需要轉換爲字符串和字符數組... – user1779502 2013-04-06 22:25:04

+0

如果存儲'c_str()'的結果,請確保您創建了單獨的字符串。 – chris 2013-04-06 22:25:17

回答

4

對於std::string

ob_stream.str();

用於char數組:

ob_stream.str().c_str();