Kevin Dominic의 Studying Rock Drill~

std::stringstream 사용법 본문

Study/전공

std::stringstream 사용법

Kevin Dominic 2012. 7. 8. 00:57

출처 : http://yegam400.tistory.com/523

----------------------------------------------------------------------------------------------------

STL을 사용할때 buffer와 sprintf를 사용하는 대신에 stringstream을 사용하는데 이것의 사용법은 대충 알았었는데 초기화를 몰라서 얼마전에 찾았다. 아래와 같이 사용하고, 초기화를 하면 재사용을 할수 있다.

 

#include <sstream>

 

std::stringstream ss;
std::string data="1";

ss << "value:" << data;
// ss.str()를 하면 std::string으로 리턴된다.
OutputDebugStringA(ss.str().c_str());

//초기화. ss.clear()를 하면 초기화가 되지 않음
ss.str("");
//초기화 된 상태에서 다른 목적으로 재사용 가능
ss << ...