2013-03-11 81 views
0

請考慮下面的代碼:提取整個的std :: string從一個std :: stringstream的

std::stringstream test; 
test << std::string("This is a test."); 
std::string str; 
test >> str; 
std::cout << "\"" << str << "\"" << std::endl; 

這僅輸出字符串 「This」,而不是 「這是一個測試。」

這是怎麼回事,我怎麼能得到整個字符串?

回答

5

std::stringstream::str

std::string str = test.str(); 
+0

OK,應該已經看到了未來。我太簡化了我的例子。請看這裏: http://stackoverflow.com/questions/15350927/member-function-template-to-covert-a-stdstring-to-any-numeric-type-or-to-a-std – Dave 2013-03-12 00:04:36

相關問題