🌍 C++ Study/C++ 기초
C++ 의 스트링빌더 std::stringstream
맨텀
2024. 11. 10. 02:01
C#의 StringBuilder와 대응되는 기능을 가진 객체로 <sstream> 헤더에 몇가지 객체가 있다.
대표적으로
std::stringstream 과
std::ostringstream 이 있는데,
둘 다 std::iostream 을 상속받았지만
차이점은 전자는 입출력이 가능하고, 후자는 출력전용이다.
비워줄 때는 C#의 StringBuilder랑 동일하게 clear() 를 호출하면된다.
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
int main(void) {
string str;
int n;
cin >> str >> n;
std::ostringstream oss;
for (int i = 0; i < n; ++i)
oss << str;
cout << oss.str() << endl;
return 0;
}