Write a C++ program to read a text file "input.txt" and store
the data in form of 2d array (or any other data structure you
prefer).
Input file:
a0 400 1 0 20
a1 300 2 0 30
a2 200 3 0 40
a3 100 6 0 40
a4 0 7 0 50
#include<iostream>
#include<fstream>
using namespace std;
int main()
{
ifstream myFile ("input.txt", ios::in);
//reading file
string arr[5][5];
{
for (int r = 0; r<5; r++)
{
for (int c = 0; c < 5; c++)
{
myFile >> arr[r][c];
}
}
myFile.close();
}
for(int r = 0;r<5;r++)
{
for(int c = 0;c<5;c++)
{
cout << arr[r][c] << " ";
}
cout << "\n";
}
}
Get Answers For Free
Most questions answered within 1 hours.