I strongly suspect you want something capable of parsing a grammar; Here's with Boost Spirit X3:
Live On Coliru
#include <boost/spirit/home/x3.hpp>
#include <boost/tuple/tuple_io.hpp>
#include <boost/fusion/adapted/boost_tuple.hpp>
#include <iostream>
namespace std {
// hack for debug output
std::ostream& operator<<(std::ostream& os, std::vector<std::string> const& v) {
for (auto i = 0ul; i<v.size(); ++i) {
if (i) os << " ";
os << v[i];
}
return os;
}
}
namespace x3 = boost::spirit::x3;
int main() {
std::string const input = "123 10.03.1 TEXT1 TEXT2 TEXT3 TEXT4 TEXT5 \t \tTEXT6 2015/10/10 \t 2012";
int num;
std::string version;
std::vector<std::string> texts;
std::string date;
int year;
auto attr = boost::tie(num, version, texts, date, year);
bool ok = false;
{
using namespace x3;
auto date_ = raw [ repeat(4) [ digit ] >> '/' >> repeat(2) [ digit ] >> '/' >> repeat(2) [ digit ] ];
auto version_ = lexeme [ +char_("0-9.") ];
auto text_ = lexeme [ alpha >> *alnum ];
ok = phrase_parse(input.begin(), input.end(),
int_ >> version_ >> *text_ >> date_ >> int_ /* >> eoi */,
x3::space,
attr);
}
if (ok) {
std::cout << "parsed: " << attr << "\n";
} else {
std::cout << "parse failed\n";
}
}
Prints
parsed: (123 10.03.1 TEXT1 TEXT2 TEXT3 TEXT4 TEXT5 TEXT6 2015/10/10 2012)
Note how this does much more than just split up your input. It ignores whitespace where required, assigns the converted values to integers, puts the TEXTn
elements in a vector etc.
You can also parse these from a stream if you care (see boost::spirit::istream_iterator
).
\S+
to match a nonwhitespace chunk of text. – Wiktor Stribiżew