c++模版 根据特殊字符拆分和组合字符串,储存在vector容器

#include 
#include 
#include 
template
std::vector splitString(const std::string& str, char delimiter)
{
	std::vector tokens;
	std::stringstream ss(str);
	std::string token;

	while (std::getline(ss, token, delimiter))
	{
		std::stringstream converter(token);
		T value;
		converter >> value;
		tokens.push_back(value);
	}

	return tokens;
}

template 
class VectorToStringConverter
{
public:
	static std::string convert(const std::vector& vec, char delimiter)
	{
		std::stringstream ss;
		for (typename std::vector::const_iterator it = vec.begin(); it != vec.end(); ++it)
		{
			if (it != vec.begin())
				ss << delimiter;
			ss << *it;
		}
		return ss.str();
	}
};

你可能感兴趣的:(c++,开发语言)