Let's say I have a txt file
Rahim
5 6 7
Karim
6 7 8
Rahman
7 8 9
I want to save those name in a vector and I want to put those number in a nested vector as integers.
I tried this but it's not working.
#include <string>
#include <vector>
using namespace std;
int main(){
vector<vector<int> > data;
vector<int> temp;
vector<string> nameF;
string file;
cout << "Enter a file: ";
cin >> file;
ifstream infile(file);
if(!infile.good()){
cout << "Enter a valid file: " << endl;
return 1;
}
string name;
string values;
while(!infile.eof()){
getline(infile, name);
getline(infile, values);
if(!infile.fail()){
nameF.push_back(name);
for(int i = 0; i < values.length(); i++){
string s = values.substr(i, values.find(" "));
temp.push_back(stoi(s));
}
data.push_back(temp);
}
}
}