boost - How to save strings in array after tokenizing it c++? -


my input.txt file looks this.

"55.2""4""1""0""d""e""a" 

so wrote small cpp tokenize boost.

#include <iostream>     // cout, endl #include <fstream>      // fstream #include <vector> #include <string> #include <algorithm>    // copy #include <iterator>     // ostream_operator  #include <boost/tokenizer.hpp>  int main() {     using namespace std;     using namespace boost;      string data("input.txt");      ifstream in(data.c_str());     if (!in.is_open()) return 1;     typedef tokenizer< escaped_list_separator<char> > tokenizer;      vector< string > vec;     string line;      while (getline(in,line))     {         tokenizer tok(line);         vec.assign(tok.begin(),tok.end());          if (vec.size() < 1) continue;          copy(vec.begin(), vec.end(),               ostream_iterator<string>(cout, "-"));         cout << "\n" << endl;     } } 

till awesome. output:

55.2-4-1-0-d-e-a 

but couldn't figure out how save each token in array. ex:

a[0]=55.2 a[1]=4 a[2]=1 a[3]=0 a[4]=d a[5]=e a[6]=a 

edit: may question not clear. want parse individual data , use in other places need save them array can access them when ever want.

if intrested.

cout  << vec[0] << endl; 

it display first token. @barry


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -