c++ - Generate appropriate number of tokens using boost -


i have code below

 std::string some_string = "-0.003  79350   -0.267  147";  boost::algorithm::trim (some_string);  //std::cout << some_string << std::endl;  boost::tokenizer<> tok( some_string );  const auto n = std::distance( tok.begin(), tok.end() );  std::cout << n << std::endl; 

i wish have number of tokens 4, gives 6 . suggestions appreciated. thanks.

the following code outputs 4 required.

#include<iostream> #include<string> #include<boost/tokenizer.hpp>  int main() {    std::string s = "-0.003  79350   -0.267  147";    boost::tokenizer<boost::char_separator<char> > tok(s, boost::char_separator<char>(" "));    const auto n = std::distance( tok.begin(), tok.end() );    std::cout << n << std::endl; } 

the same code on coliru here.


Comments

Popular posts from this blog

tcpdump - How to check if server received packet (acknowledged) -