C++

특정 문자 ',', '/' 등으로 문자열 분할 후 배열에 차례로 집어넣는 함수

전유댕 2024. 2. 21. 18:38
vector<int> split(const string& str, char sep)
{
	vector<int> tokens;

	int i;
	stringstream ss(str);
	while (ss >> i) {
		tokens.push_back(i);
		if (ss.peek() == sep) {
			ss.ignore();
		}
	}

	return tokens;
}