分割函数C ++ [英] split function for C++
本文介绍了分割函数C ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有类似于Java的C ++的拆分类型函数吗?我知道忽略,但我不太明白它,以及它将如何为我的情况工作。
Is there a split type function for C++ similar to Java? I know of ignore, but I don't quite understand it, and how it'll work for my case.
我的输入是:
{
item = ball
book = lord of the rings
movie = star wars
}
我输入的是< attribute>
= < value>
,我必须将这两个存储在不同的字符串或整数(取决于值,例如,如果它的一个数字,使用整数) / p>
My input given is an <attribute>
= <value>
and I have to store the two in different strings, or integers (depending on the value, for example, if its a number, use an integer).
推荐答案
使用 Boost :: tokenizer ,因为它做了你想做的事情。从手册:
Use Boost::tokenizer as it does what you want to do. From the manual:
// 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 ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文