c++ - reading two vectors from file -


problem described here. tried solve using code that's below, it's not working.

const char* filename = "test.txt"; ifstream file1(filename); vector<int> v1; vector<int> v2; vector<int> res;  int number; char c;  while(1){     while(1){         v1.push_back(number);         file1.get(c);         if (c==';') break;     }      while(1){         v2.push_back(number);         file1.get(c);         if (c=='\n') break;     }      (vector<int>::iterator = v2.begin(); it!=v2.end(); it++)         cout << *it << ',';     cout << endl;     file1.get(c);     if (c==eof) break;     file1.unget(); } 

there problem reading end of line. c=='\n' right?

to read line, should use:

istream& getline (istream& is, string& str, char delim);

in case, delimiter of ';'

then can parse numbers in same way, using delimiter of ','

like this:

std::string line, temp; std::getline(file1,line,';'); //get line. (till ';') std::istringstream s1 (line); //init stream whole line while(std::getline(s1,temp,',')){//get number string line. (till ',')    int n;    std::istringstream s2(temp);    s2>>n; //convert string number numeric value    //now can push vector... } 

Comments