I have file with numbers.
3
2 15 41
4 1 2 3 4
3 22 11 24
First line show how other lines exists (max 100).
Numbers in line can not contain more than 50.
Numbers in lines need to be put into array something like:
line[lineNum][num]
I’m new in C++ and I asking to do this in simplest posible way. I tried doing:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main(int argc, char *argv[])
{
int kiek;
string str[100][50];
string line;
int a = 0;
int b = 0;
ifstream failas("Duom1.txt");
if (failas.is_open())
{
while (failas)
{
if (a == 29)
{
a = 0;
b++;
}
getline(failas, str[a][b], ' ');
}
a++;
}
cout << str[0][0] << endl;
}
Read the file line by line and then parse every line by itself.
a better approach though, would be to use
std::vectorinstead of an array: