Advertisement
Guest User

Untitled

a guest
Apr 19th, 2014
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 20.74 KB | None | 0 0
  1. std::vector<std::string> getNextLineAndSplitIntoTokens(std::istream& str)
  2. {
  3. std::vector<std::string> result;
  4. std::string line;
  5. std::getline(str,line);
  6.  
  7. std::stringstream lineStream(line);
  8. std::string cell;
  9.  
  10. while(std::getline(lineStream,cell,','))
  11. {
  12. result.push_back(cell);
  13. }
  14. return result;
  15. }
  16.  
  17. #include <iterator>
  18. #include <iostream>
  19. #include <fstream>
  20. #include <sstream>
  21. #include <vector>
  22. #include <string>
  23.  
  24. class CSVRow
  25. {
  26. public:
  27. std::string const& operator[](std::size_t index) const
  28. {
  29. return m_data[index];
  30. }
  31. std::size_t size() const
  32. {
  33. return m_data.size();
  34. }
  35. void readNextRow(std::istream& str)
  36. {
  37. std::string line;
  38. std::getline(str,line);
  39.  
  40. std::stringstream lineStream(line);
  41. std::string cell;
  42.  
  43. m_data.clear();
  44. while(std::getline(lineStream,cell,','))
  45. {
  46. m_data.push_back(cell);
  47. }
  48. }
  49. private:
  50. std::vector<std::string> m_data;
  51. };
  52.  
  53. std::istream& operator>>(std::istream& str,CSVRow& data)
  54. {
  55. data.readNextRow(str);
  56. return str;
  57. }
  58. int main()
  59. {
  60. std::ifstream file("plop.csv");
  61.  
  62. CSVRow row;
  63. while(file >> row)
  64. {
  65. std::cout << "4th Element(" << row[3] << ")n";
  66. }
  67. }
  68.  
  69. class CSVIterator
  70. {
  71. public:
  72. typedef std::input_iterator_tag iterator_category;
  73. typedef CSVRow value_type;
  74. typedef std::size_t difference_type;
  75. typedef CSVRow* pointer;
  76. typedef CSVRow& reference;
  77.  
  78. CSVIterator(std::istream& str) :m_str(str.good()?&str:NULL) { ++(*this); }
  79. CSVIterator() :m_str(NULL) {}
  80.  
  81. // Pre Increment
  82. CSVIterator& operator++() {if (m_str) { (*m_str) >> m_row;m_str = m_str->good()?m_str:NULL;}return *this;}
  83. // Post increment
  84. CSVIterator operator++(int) {CSVIterator tmp(*this);++(*this);return tmp;}
  85. CSVRow const& operator*() const {return m_row;}
  86. CSVRow const* operator->() const {return &m_row;}
  87.  
  88. bool operator==(CSVIterator const& rhs) {return ((this == &rhs) || ((this->m_str == NULL) && (rhs.m_str == NULL)));}
  89. bool operator!=(CSVIterator const& rhs) {return !((*this) == rhs);}
  90. private:
  91. std::istream* m_str;
  92. CSVRow m_row;
  93. };
  94.  
  95.  
  96. int main()
  97. {
  98. std::ifstream file("plop.csv");
  99.  
  100. for(CSVIterator loop(file);loop != CSVIterator();++loop)
  101. {
  102. std::cout << "4th Element(" << (*loop)[3] << ")n";
  103. }
  104. }
  105.  
  106. std::vector<std::string> vec;
  107. using namespace boost;
  108. tokenizer<escaped_list_separator<char> > tk(
  109. line, escaped_list_separator<char>('\', ',', '"'));
  110. for (tokenizer<escaped_list_separator<char> >::iterator i(tk.begin());
  111. i!=tk.end();++i)
  112. {
  113. vec.push_back(*i);
  114. }
  115.  
  116. void foo()
  117. {
  118. std::string data = "1,2,3,4,5n"
  119. "0,2,4,6,8n"
  120. "1,3,5,7,9n";
  121.  
  122. strtk::token_grid grid(data,data.size(),",");
  123.  
  124. for(std::size_t i = 0; i < grid.row_count(); ++i)
  125. {
  126. strtk::token_grid::row_type r = grid.row(i);
  127. for(std::size_t j = 0; j < r.size(); ++j)
  128. {
  129. std::cout << r.get<int>(j) << "t";
  130. }
  131. std::cout << std::endl;
  132. }
  133. std::cout << std::endl;
  134. }
  135.  
  136. bool r = phrase_parse(first, last,
  137.  
  138. // Begin grammar
  139. (
  140. double_ % ','
  141. )
  142. ,
  143. // End grammar
  144.  
  145. space, v);
  146.  
  147. #include <iostream> // cout, endl
  148. #include <fstream> // fstream
  149. #include <vector>
  150. #include <string>
  151. #include <algorithm> // copy
  152. #include <iterator> // ostream_operator
  153. #include <boost/tokenizer.hpp>
  154.  
  155. int main()
  156. {
  157. using namespace std;
  158. using namespace boost;
  159. string data("data.csv");
  160.  
  161. ifstream in(data.c_str());
  162. if (!in.is_open()) return 1;
  163.  
  164. typedef tokenizer< escaped_list_separator<char> > Tokenizer;
  165. vector< string > vec;
  166. string line;
  167.  
  168. while (getline(in,line))
  169. {
  170. Tokenizer tok(line);
  171. vec.assign(tok.begin(),tok.end());
  172.  
  173. // vector now contains strings from one row, output to cout here
  174. copy(vec.begin(), vec.end(), ostream_iterator<string>(cout, "|"));
  175.  
  176. cout << "n----------------------" << endl;
  177. }
  178. }
  179.  
  180. void ParseCSV(const string& csvSource, vector<vector<string> >& lines)
  181. {
  182. bool inQuote(false);
  183. bool newLine(false);
  184. string field;
  185. lines.clear();
  186. vector<string> line;
  187.  
  188. string::const_iterator aChar = csvSource.begin();
  189. while (aChar != csvSource.end())
  190. {
  191. switch (*aChar)
  192. {
  193. case '"':
  194. newLine = false;
  195. inQuote = !inQuote;
  196. break;
  197.  
  198. case ',':
  199. newLine = false;
  200. if (inQuote == true)
  201. {
  202. field += *aChar;
  203. }
  204. else
  205. {
  206. line.push_back(field);
  207. field.clear();
  208. }
  209. break;
  210.  
  211. case 'n':
  212. case 'r':
  213. if (inQuote == true)
  214. {
  215. field += *aChar;
  216. }
  217. else
  218. {
  219. if (newLine == false)
  220. {
  221. line.push_back(field);
  222. lines.push_back(line);
  223. field.clear();
  224. line.clear();
  225. newLine = true;
  226. }
  227. }
  228. break;
  229.  
  230. default:
  231. newLine = false;
  232. field.push_back(*aChar);
  233. break;
  234. }
  235.  
  236. aChar++;
  237. }
  238.  
  239. if (field.size())
  240. line.push_back(field);
  241.  
  242. if (line.size())
  243. lines.push_back(line);
  244. }
  245.  
  246. const char input[] =
  247. "Year,Make,Model,Description,Pricen"
  248. "1997,Ford,E350,"ac, abs, moon",3000.00n"
  249. "1999,Chevy,"Venture ""Extended Edition""","",4900.00n"
  250. "1999,Chevy,"Venture ""Extended Edition, Very Large""","",5000.00n"
  251. "1996,Jeep,Grand Cherokee,"MUST SELL!n
  252. air, moon roof, loaded",4799.00n"
  253. ;
  254.  
  255. std::istringstream ss(input);
  256. std::string title[5];
  257. int year;
  258. std::string make, model, desc;
  259. float price;
  260. csv_istream(ss)
  261. >> title[0] >> title[1] >> title[2] >> title[3] >> title[4];
  262. while (csv_istream(ss)
  263. >> year >> make >> model >> desc >> price) {
  264. //...do something with the record...
  265. }
  266.  
  267. struct csv_istream {
  268. std::istream &is_;
  269. csv_istream (std::istream &is) : is_(is) {}
  270. void scan_ws () const {
  271. while (is_.good()) {
  272. int c = is_.peek();
  273. if (c != ' ' && c != 't') break;
  274. is_.get();
  275. }
  276. }
  277. void scan (std::string *s = 0) const {
  278. std::string ws;
  279. int c = is_.get();
  280. if (is_.good()) {
  281. do {
  282. if (c == ',' || c == 'n') break;
  283. if (s) {
  284. ws += c;
  285. if (c != ' ' && c != 't') {
  286. *s += ws;
  287. ws.clear();
  288. }
  289. }
  290. c = is_.get();
  291. } while (is_.good());
  292. if (is_.eof()) is_.clear();
  293. }
  294. }
  295. template <typename T, bool> struct set_value {
  296. void operator () (std::string in, T &v) const {
  297. std::istringstream(in) >> v;
  298. }
  299. };
  300. template <typename T> struct set_value<T, true> {
  301. template <bool SIGNED> void convert (std::string in, T &v) const {
  302. if (SIGNED) v = ::strtoll(in.c_str(), 0, 0);
  303. else v = ::strtoull(in.c_str(), 0, 0);
  304. }
  305. void operator () (std::string in, T &v) const {
  306. convert<is_signed_int<T>::val>(in, v);
  307. }
  308. };
  309. template <typename T> const csv_istream & operator >> (T &v) const {
  310. std::string tmp;
  311. scan(&tmp);
  312. set_value<T, is_int<T>::val>()(tmp, v);
  313. return *this;
  314. }
  315. const csv_istream & operator >> (std::string &v) const {
  316. v.clear();
  317. scan_ws();
  318. if (is_.peek() != '"') scan(&v);
  319. else {
  320. std::string tmp;
  321. is_.get();
  322. std::getline(is_, tmp, '"');
  323. while (is_.peek() == '"') {
  324. v += tmp;
  325. v += is_.get();
  326. std::getline(is_, tmp, '"');
  327. }
  328. v += tmp;
  329. scan();
  330. }
  331. return *this;
  332. }
  333. template <typename T>
  334. const csv_istream & operator >> (T &(*manip)(T &)) const {
  335. is_ >> manip;
  336. return *this;
  337. }
  338. operator bool () const { return !is_.fail(); }
  339. };
  340.  
  341. template <typename T> struct is_signed_int { enum { val = false }; };
  342. template <> struct is_signed_int<short> { enum { val = true}; };
  343. template <> struct is_signed_int<int> { enum { val = true}; };
  344. template <> struct is_signed_int<long> { enum { val = true}; };
  345. template <> struct is_signed_int<long long> { enum { val = true}; };
  346.  
  347. template <typename T> struct is_unsigned_int { enum { val = false }; };
  348. template <> struct is_unsigned_int<unsigned short> { enum { val = true}; };
  349. template <> struct is_unsigned_int<unsigned int> { enum { val = true}; };
  350. template <> struct is_unsigned_int<unsigned long> { enum { val = true}; };
  351. template <> struct is_unsigned_int<unsigned long long> { enum { val = true}; };
  352.  
  353. template <typename T> struct is_int {
  354. enum { val = (is_signed_int<T>::val || is_unsigned_int<T>::val) };
  355. };
  356.  
  357. void loadFromCSV( const std::string& filename )
  358. {
  359. std::ifstream file( filename.c_str() );
  360. std::vector< std::vector<std::string> > matrix;
  361. std::vector<std::string> row;
  362. std::string line;
  363. std::string cell;
  364.  
  365. while( file )
  366. {
  367. std::getline(file,line);
  368. std::stringstream lineStream(line);
  369. row.clear();
  370.  
  371. while( std::getline( lineStream, cell, ',' ) )
  372. row.push_back( cell );
  373.  
  374. if( !row.empty() )
  375. matrix.push_back( row );
  376. }
  377.  
  378. for( int i=0; i<int(matrix.size()); i++ )
  379. {
  380. for( int j=0; j<int(matrix[i].size()); j++ )
  381. std::cout << matrix[i][j] << " ";
  382.  
  383. std::cout << std::endl;
  384. }
  385. }
  386.  
  387. /**
  388.  
  389. Read line from a CSV file
  390.  
  391. @param[in] fp file pointer to open file
  392. @param[in] vls reference to vector of strings to hold next line
  393.  
  394. */
  395. void readCSV( FILE *fp, std::vector<std::string>& vls )
  396. {
  397. vls.clear();
  398. if( ! fp )
  399. return;
  400. char buf[10000];
  401. if( ! fgets( buf,999,fp) )
  402. return;
  403. std::string s = buf;
  404. int p,q;
  405. q = -1;
  406. // loop over columns
  407. while( 1 ) {
  408. p = q;
  409. q = s.find_first_of(",n",p+1);
  410. if( q == -1 )
  411. break;
  412. vls.push_back( s.substr(p+1,q-p-1) );
  413. }
  414. }
  415.  
  416. int _tmain(int argc, _TCHAR* argv[])
  417. {
  418. std::vector<std::string> vls;
  419. FILE * fp = fopen( argv[1], "r" );
  420. if( ! fp )
  421. return 1;
  422. readCSV( fp, vls );
  423. readCSV( fp, vls );
  424. readCSV( fp, vls );
  425. std::cout << "row 3, col 4 is " << vls[3].c_str() << "n";
  426.  
  427. return 0;
  428. }
  429.  
  430. #include "csv.h"
  431.  
  432. int main(){
  433. io::CSVReader<3> in("ram.csv");
  434. in.read_header(io::ignore_extra_column, "vendor", "size", "speed");
  435. std::string vendor; int size; double speed;
  436. while(in.read_row(vendor, size, speed)){
  437. // do stuff with the data
  438. }
  439. }
  440.  
  441. #include <string>
  442. #include <sstream>
  443. #include <fstream>
  444.  
  445. void StringReplace(std::string& str, const std::string& oldStr, const std::string& newStr)
  446. // code by Yves Baumes
  447. // http://stackoverflow.com/questions/1494399/how-do-i-search-find-and-replace-in-a-standard-string
  448. {
  449. size_t pos = 0;
  450. while((pos = str.find(oldStr, pos)) != std::string::npos)
  451. {
  452. str.replace(pos, oldStr.length(), newStr);
  453. pos += newStr.length();
  454. }
  455. }
  456.  
  457. void LoadCSV(std::string &filename) {
  458. std::ifstream stream(filename);
  459. std::string in_line;
  460. std::string Field;
  461. std::string Chan;
  462. int ChanType;
  463. double Scale;
  464. int Import;
  465. while (std::getline(stream, in_line)) {
  466. StringReplace(in_line, ",", " ");
  467. std::stringstream line(in_line);
  468. line >> Field >> Chan >> ChanType >> Scale >> Import;
  469. if (Field.substr(0,2)!="//") {
  470. // do your stuff
  471. // this is CBuilder code for demonstration, sorry
  472. ShowMessage((String)Field.c_str() + "n" + Chan.c_str() + "n" + IntToStr(ChanType) + "n" +FloatToStr(Scale) + "n" +IntToStr(Import));
  473. }
  474. }
  475. }
  476.  
  477. using namespace std;
  478.  
  479. // trim whitespaces around field or double-quotes, remove double-quotes and replace escaped double-quotes (double double-quotes)
  480. wstring trimquote(const wstring& str, const wstring& whitespace, const wchar_t quotChar)
  481. {
  482. wstring ws;
  483. wstring::size_type strBegin = str.find_first_not_of(whitespace);
  484. if (strBegin == wstring::npos)
  485. return L"";
  486.  
  487. wstring::size_type strEnd = str.find_last_not_of(whitespace);
  488. wstring::size_type strRange = strEnd - strBegin + 1;
  489.  
  490. if((str[strBegin] == quotChar) && (str[strEnd] == quotChar))
  491. {
  492. ws = str.substr(strBegin+1, strRange-2);
  493. strBegin = 0;
  494. while((strEnd = ws.find(quotChar, strBegin)) != wstring::npos)
  495. {
  496. ws.erase(strEnd, 1);
  497. strBegin = strEnd+1;
  498. }
  499.  
  500. }
  501. else
  502. ws = str.substr(strBegin, strRange);
  503. return ws;
  504. }
  505.  
  506. pair<unsigned, unsigned> nextCSVQuotePair(const wstring& line, const wchar_t quotChar, unsigned ofs = 0)
  507. {
  508. pair<unsigned, unsigned> r;
  509. r.first = line.find(quotChar, ofs);
  510. r.second = wstring::npos;
  511. if(r.first != wstring::npos)
  512. {
  513. r.second = r.first;
  514. while(((r.second = line.find(quotChar, r.second+1)) != wstring::npos)
  515. && (line[r.second+1] == quotChar)) // WARNING: assumes null-terminated string such that line[r.second+1] always exist
  516. r.second++;
  517.  
  518. }
  519. return r;
  520. }
  521.  
  522. unsigned parseLine(vector<wstring>& fields, const wstring& line)
  523. {
  524. unsigned ofs, ofs0, np;
  525. const wchar_t delim = L',';
  526. const wstring whitespace = L" txa0x3000x2000x2001x2002x2003x2004x2005x2006x2007x2008x2009x200ax202fx205f";
  527. const wchar_t quotChar = L'"';
  528. pair<unsigned, unsigned> quot;
  529.  
  530. fields.clear();
  531.  
  532. ofs = ofs0 = 0;
  533. quot = nextCSVQuotePair(line, quotChar);
  534. while((np = line.find(delim, ofs)) != wstring::npos)
  535. {
  536. if((np > quot.first) && (np < quot.second))
  537. { // skip delimiter inside quoted field
  538. ofs = quot.second+1;
  539. quot = nextCSVQuotePair(line, quotChar, ofs);
  540. continue;
  541. }
  542. fields.push_back( trimquote(line.substr(ofs0, np-ofs0), whitespace, quotChar) );
  543. ofs = ofs0 = np+1;
  544. }
  545. fields.push_back( trimquote(line.substr(ofs0), whitespace, quotChar) );
  546.  
  547. return fields.size();
  548. }
  549.  
  550. #include <stdbool.h>
  551. #include <wchar.h>
  552. #include <wctype.h>
  553.  
  554. extern const wchar_t *nextCsvField(const wchar_t *p, wchar_t sep, bool *newline);
  555.  
  556. // Returns a pointer to the start of the next field,
  557. // or zero if this is the last field in the CSV
  558. // p is the start position of the field
  559. // sep is the separator used, i.e. comma or semicolon
  560. // newline says whether the field ends with a newline or with a comma
  561. const wchar_t *nextCsvField(const wchar_t *p, wchar_t sep, bool *newline)
  562. {
  563. // Parse quoted sequences
  564. if ('"' == p[0]) {
  565. p++;
  566. while (1) {
  567. // Find next double-quote
  568. p = wcschr(p, L'"');
  569. // If we don't find it or it's the last symbol
  570. // then this is the last field
  571. if (!p || !p[1])
  572. return 0;
  573. // Check for "", it is an escaped double-quote
  574. if (p[1] != '"')
  575. break;
  576. // Skip the escaped double-quote
  577. p += 2;
  578. }
  579. }
  580.  
  581. // Find next newline or comma.
  582. wchar_t newline_or_sep[4] = L"nr ";
  583. newline_or_sep[2] = sep;
  584. p = wcspbrk(p, newline_or_sep);
  585.  
  586. // If no newline or separator, this is the last field.
  587. if (!p)
  588. return 0;
  589.  
  590. // Check if we had newline.
  591. *newline = (p[0] == 'r' || p[0] == 'n');
  592.  
  593. // Handle "rn", otherwise just increment
  594. if (p[0] == 'r' && p[1] == 'n')
  595. p += 2;
  596. else
  597. p++;
  598.  
  599. return p;
  600. }
  601.  
  602. static wchar_t *csvFieldData(const wchar_t *fld_s, const wchar_t *fld_e, wchar_t *buffer, size_t buflen)
  603. {
  604. wchar_t *dst = buffer;
  605. wchar_t *end = buffer + buflen - 1;
  606. const wchar_t *src = fld_s;
  607.  
  608. if (*src == L'"')
  609. {
  610. const wchar_t *p = src + 1;
  611. while (p < fld_e && dst < end)
  612. {
  613. if (p[0] == L'"' && p+1 < fld_s && p[1] == L'"')
  614. {
  615. *dst++ = p[0];
  616. p += 2;
  617. }
  618. else if (p[0] == L'"')
  619. {
  620. p++;
  621. break;
  622. }
  623. else
  624. *dst++ = *p++;
  625. }
  626. src = p;
  627. }
  628. while (src < fld_e && dst < end)
  629. *dst++ = *src++;
  630. if (dst >= end)
  631. return 0;
  632. *dst = L'';
  633. return(buffer);
  634. }
  635.  
  636. static void dissect(const wchar_t *line)
  637. {
  638. const wchar_t *start = line;
  639. const wchar_t *next;
  640. bool eol;
  641. wprintf(L"Input %3zd: [%.*ls]n", wcslen(line), wcslen(line)-1, line);
  642. while ((next = nextCsvField(start, L',', &eol)) != 0)
  643. {
  644. wchar_t buffer[1024];
  645. wprintf(L"Raw Field: [%.*ls] (eol = %d)n", (next - start - eol), start, eol);
  646. if (csvFieldData(start, next-1, buffer, sizeof(buffer)/sizeof(buffer[0])) != 0)
  647. wprintf(L"Field %3zd: [%ls]n", wcslen(buffer), buffer);
  648. start = next;
  649. }
  650. }
  651.  
  652. static const wchar_t multiline[] =
  653. L"First field of first row,"This field is multilinen"
  654. "n"
  655. "but that's OK because it's enclosed in double quotes, and thisn"
  656. "is an escaped "" double quote" but this one "" is notn"
  657. " "This is second field of second row, but it is not multilinen"
  658. " because it doesn't start n"
  659. " with an immediate double quote"n"
  660. ;
  661.  
  662. int main(void)
  663. {
  664. wchar_t line[1024];
  665.  
  666. while (fgetws(line, sizeof(line)/sizeof(line[0]), stdin))
  667. dissect(line);
  668. dissect(multiline);
  669.  
  670. return 0;
  671. }
  672.  
  673. #include <sstream>
  674. #include <fstream>
  675. #include <iterator>
  676. #include <string>
  677. #include <vector>
  678. #include <algorithm>
  679.  
  680. using namespace std;
  681.  
  682. /**
  683. * Parse a CSV data file and fill the 2d STL vector "data".
  684. * Limits: only "pure datas" of doubles, not encapsulated by " and without n inside.
  685. * Further no formatting in the data (e.g. scientific notation)
  686. * It however handles both dots and commas as decimal separators and removes thousand separator.
  687. *
  688. * returnCodes[0]: file access 0-> ok 1-> not able to read; 2-> decimal separator equal to comma separator
  689. * returnCodes[1]: number of records
  690. * returnCodes[2]: number of fields. -1 If rows have different field size
  691. *
  692. */
  693. vector<int>
  694. readCsvData (vector <vector <double>>& data, const string& filename, const string& delimiter, const string& decseparator){
  695.  
  696. int vv[3] = { 0,0,0 };
  697. vector<int> returnCodes(&vv[0], &vv[0]+3);
  698.  
  699. string rowstring, stringtoken;
  700. double doubletoken;
  701. int rowcount=0;
  702. int fieldcount=0;
  703. data.clear();
  704.  
  705. ifstream iFile(filename, ios_base::in);
  706. if (!iFile.is_open()){
  707. returnCodes[0] = 1;
  708. return returnCodes;
  709. }
  710. while (getline(iFile, rowstring)) {
  711. if (rowstring=="") continue; // empty line
  712. rowcount ++; //let's start with 1
  713. if(delimiter == decseparator){
  714. returnCodes[0] = 2;
  715. return returnCodes;
  716. }
  717. if(decseparator != "."){
  718. // remove dots (used as thousand separators)
  719. string::iterator end_pos = remove(rowstring.begin(), rowstring.end(), '.');
  720. rowstring.erase(end_pos, rowstring.end());
  721. // replace decimal separator with dots.
  722. replace(rowstring.begin(), rowstring.end(),decseparator.c_str()[0], '.');
  723. } else {
  724. // remove commas (used as thousand separators)
  725. string::iterator end_pos = remove(rowstring.begin(), rowstring.end(), ',');
  726. rowstring.erase(end_pos, rowstring.end());
  727. }
  728. // tokenize..
  729. vector<double> tokens;
  730. // Skip delimiters at beginning.
  731. string::size_type lastPos = rowstring.find_first_not_of(delimiter, 0);
  732. // Find first "non-delimiter".
  733. string::size_type pos = rowstring.find_first_of(delimiter, lastPos);
  734. while (string::npos != pos || string::npos != lastPos){
  735. // Found a token, convert it to double add it to the vector.
  736. stringtoken = rowstring.substr(lastPos, pos - lastPos);
  737. if (stringtoken == "") {
  738. tokens.push_back(0.0);
  739. } else {
  740. istringstream totalSString(stringtoken);
  741. totalSString >> doubletoken;
  742. tokens.push_back(doubletoken);
  743. }
  744. // Skip delimiters. Note the "not_of"
  745. lastPos = rowstring.find_first_not_of(delimiter, pos);
  746. // Find next "non-delimiter"
  747. pos = rowstring.find_first_of(delimiter, lastPos);
  748. }
  749. if(rowcount == 1){
  750. fieldcount = tokens.size();
  751. returnCodes[2] = tokens.size();
  752. } else {
  753. if ( tokens.size() != fieldcount){
  754. returnCodes[2] = -1;
  755. }
  756. }
  757. data.push_back(tokens);
  758. }
  759. iFile.close();
  760. returnCodes[1] = rowcount;
  761. return returnCodes;
  762. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement