Text File Matrix into 2d Vectors

its done no need
Last edited on
Use getline(...) in the first loop and stringstream in the second:
1
2
3
4
5
6
7
8
9
10
11
12
  std::vector<std::vector<string>> array;
		std::string line;
		while(getline(filein,line)){ // go through each line
			array.emplace_back(); // an empty line will be created
			stringstream ss{line};
			string num;
			while(getline(ss,num,',')){
			
			array.back().push_back(num);
			cout << array.back().back() << endl;
			}
		}
Not tested

For stringstream see:
http://www.cplusplus.com/reference/sstream/stringstream/?kw=stringstream
Topic archived. No new replies allowed.