Hello,
I have to parsing (and to do something) with lines read from a file like 10,50,30,4 (10,22,3,^,22 -> the ^ means the line contains an error so I have to reject it)...
My code seems ok and it's this:
Qt Code:
  1. const char delim=',';
  2. void myFunction(vector<string>& lineOfFile, const char& delim) {
  3. vector<string>::iterator it = lineOfFile.begin();
  4. for( ;it != lineOfFile.end(); ++it) {
  5. vector<double> line;
  6. size_t pStart=-1;
  7. size_t pEnd=-2;
  8. double val;
  9. string subStr("");
  10. bool lineIsOk = true;
  11. while (pEnd != -1 && lineIsOk) {
  12. pStart = (int) (*it).find(delim, pStart+1);
  13. pEnd = (int) (*it).find(delim, pStart+1);
  14. subStr = (*it).substr(pStart+1, pEnd-1 - pStart );
  15. if (subStr != "^" ) {
  16. val = (double) atof( subStr.c_str() );
  17. subStr="";
  18. line.push_back(val);
  19. }
  20. else { lineIsOk = false; }
  21. }
  22. if ( lineIsOk) insertInOtherStruvture(line);
  23. }
To copy to clipboard, switch view to plain text mode 
Problem now is that this is working only delim=',' and I'd like parsing that line in way like mine (it seems simple, doens't it?) but with other delim for example, I'd like cover line like
10 2 22 200 1
or
10 space space space 22 space 2 33
if the creator of file don't create the file correct with more space (but I'd like to parse it how it was)



Could you help me, please? thanks a lot.