C++有类似Java的split类型函数吗?我知道忽略,但我不太了解它,以及它如何适用于我的情况。
我的输入是:
{
item = ball
book = lord of the rings
movie = star wars
}
我给出的输入是 <attribute>
= <value>
我必须将两者存储在不同的字符串或整数中(取决于值,例如,如果它是数字,则使用整数)。
最佳答案
使用Boost::tokenizer因为它做你想做的事。来自手册:
// simple_example_1.cpp
#include<iostream>
#include<boost/tokenizer.hpp>
#include<string>
int main(){
using namespace std;
using namespace boost;
string s = "This is, a test";
tokenizer<> tok(s);
for(tokenizer<>::iterator beg=tok.begin(); beg!=tok.end();++beg){
cout << *beg << "\n";
}
}
关于c++ - C++ 的拆分函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7583090/