일단 하자

[C++] string에서 int로 형변환하기 본문

코딩꿀팁

[C++] string에서 int로 형변환하기

coredump064 2019. 11. 28. 23:20
#include <iostream>
#include <sstream>
using namespace std;

template <typename T>
string toString(const T& value) {
	ostringstream oss;
	oss << value;
	return oss.str();
}

int main(void) {
	int size = 100000;
	string fileName = "list" + toString(size) + ".txt";
	cout << fileName;
}

to_string등 여러가지 함수가 있는데 stream연산자를 이용한 형변환 template 함수를 그냥 만들어서 하는 방법도 있다.

Comments