搞了搞split,發現boost里邊已經有了,就拿過來直接用,之前翻了下facebook的,也沒見比boost更容易讀,還是boost算了。
在vs2012上編譯了一下,發現有問題:error C4996: 'std::_Copy_impl': Function call with para
找了下,老外是這么說的:http://stackoverflow.com/questions/14141476/warning-with-boostsplit-when-compiling
You haven't done anything wrong. Visual Studio is being overly cautious. In debug mode, visual studio uses something called "Checked Iterators". Pointers are also iterators, but the checking mechanism doesn't work with them. So when a standard library algorithm is called with pointers, which is something that boost::split
does, it issues this warning.
You'll get the same warning with this obviously safe code:
int main()
{
int x[10] = {};
int y[10] = {};
int *a = x, *b = y;
std::copy(a, a+10, b);
}
Disable the warning. It's for beginners. It's on by default for the safety of beginners, because if it was off by default, they wouldn't know how to turn it on.
#include <boost/algorithm/string/classification.hpp>
#include <boost/algorithm/string.hpp>
void LearnSplit()
{
std::string strTem("1,2,3,4");
std::list<std::string> listStrTem;
std::vector<std::string> vectorStrTem;
boost::split(listStrTem, strTem, boost::is_any_of(","));
boost::split(vectorStrTem, strTem, boost::is_any_of(","));
for(auto item : listStrTem)
{
std::cout << item.c_str() << std::endl;
}
std::string s = "Hello, the beautiful world!";
std::vector<std::string> rs;
boost::split( rs, s, boost::is_any_of( " ,!" ), boost::token_compress_on );
}
int _tmain(int argc, _TCHAR* argv[])
{
LearnSplit();
return 0;
}