What is the best way to create a formatted read / write data function for a tabular text file. Say a few calls like:
readElement(i,j)
insertRow(elem[])
readColHeaders()
I was wondering if any existing shell can do this?
internal format - tab delimited data or CSV.
Thnx-egon
There are many csv readers, but I never found something nice.
The easiest way is to use boost :: tokenize to populate the vector <vector <string β from your file. Itβs best to use boost :: spirit (but the learning curve is a roller coaster).
To generate a sur file, iterating over the vector <vector <string β is pretty trivial.
/ csv C ++. , - , , . csv, , . - , , , :
boost:: any. , , , scanf. . boost:: tokenize boost:: lexical_cast . , csv , .
get(), any_cast .
, ,
" " , , β . , , CUSIP , , .
, ()
, , , /.
, /
,
, , perl, , 10 10 perl. csv ++, .
...
#include <vector> #include <string> #include <sstream> #include <iostream> typedef std::vector<std::string> StringVec; typedef std::vector<StringVec> RowVec; RowVec readRows(std::istream& f) { std::string line; RowVec rows; while (std::getline(f, line)) { rows.push_back(StringVec()); std::string entry; std::istringstream linestrm(line); while (std::getline(linestrm, entry, '\t')) { rows.back().push_back(entry); } } return rows; } int main() { std::istringstream textFile("a\tb\tc\n1\t2\t3"); RowVec rows = readRows(textFile); std::cout << rows.size() << std::endl; std::cout << rows[0][0] << std::endl; std::cout << rows[1][2] << std::endl; return 0; }
(, ), . boost::numeric::ublas::matrix<std::string> std::vector<std::vector<std::string> >
boost::numeric::ublas::matrix<std::string>
std::vector<std::vector<std::string> >
Boost.Spirit . , :
boost::spirit::qi::phrase_parse( begin, end, // parse rule: *(char_ - '\t') % '\t' // end parse rule space, vec);`
: http://www.boost.org/doc/libs/1_46_0/libs/spirit/doc/html/spirit/qi/tutorials.html
Source: https://habr.com/ru/post/1794438/More articles:Java: defer to bytes [] - javaLow-level text engine for tablets - androidPersistence for Silverlight - silverlightandroid activity switching direction - androidBest practice for graphical if-statments in MVC 3 - asp.net-mvcrun python module without pyc extension - pythonASP.NET MVC 3 - Problem with URL Routing - asp.net-mvchow to use achart engine in android - androidCreating a calendar event - android- [UIImage CGImage] returns zero - iphoneAll Articles