#include <iostream>
#include<sstream>
#include<string>
#include<vector>
#include <fstream>
int main()
{
std::ifstream inputFile("input.txt");
std::string line;
//create a 2D vector
std::vector<std::vector<int>> arr;
int num = 0; //this will hold the current integer value from the file
std::string numTemp;
if(inputFile)
{
while(std::getline(inputFile, line)) //read line by line
{
std::vector<int> temp;//create a 1D vector
std::istringstream ss(line);
while(std::getline(ss, numTemp, '|') && (std::istringstream(numTemp) >> num)) //read integer by integer
{
//emplace_back the current number num to the temp vector
temp.emplace_back(num);
}
//emplace_back the current 1D vector temp to the 2D vector arr
arr.emplace_back(temp);
}
}
else
{
std::cout<<"input file cannot be opened"<<std::endl;
}
//lets confirm if our 2D vector contains all the elements correctly
for(const auto& row: arr)
{
for(const auto& col: row)
{
std::cout<<col<<" ";
}
std::cout<<std::endl;
}
return 0;
}
1|11|2|13|2|2|2|11|13|2
1|11|2|13|2|2|2|13|2|11
1|13|1|13|2|2|2|2|2|2
1|13|1|12|2|2|2|2|2|2
1|13|1|13|1|2|2|2|2|2
1|13|1|13|1|1|2|2|2|2
1|13|1|13|1|1|1|2|2|2
1|13|1|13|1|1|1|1|2|2
1|13|1|13|1|1|1|1|1|2
1|13|1|13|1|1|1|1|1|1