#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
const int max_rows = 38;
const int max_columns = 3;
string companies[max_rows][max_columns];
string line;
string::size_type start, end;
// Inputting file contents
ifstream file("companies.txt");
int rows = 0;
while (rows < max_rows && getline(file, line))
{
start = 0;
for(int j = 0; j < max_columns; ++j)
{
end = line.find(',', start);
companies[rows][j] = line.substr(start, end-start);
start = end + 1;
}
++rows;
}
file.close();
cout << endl << endl;
// displaying file contents using for loop
for(int i = 0; i < rows; ++i)
{
for(int j = 0; j < max_columns; ++j)
{
cout << companies[i][j] << endl << endl;
}
}
cout << endl << endl;
return 0;
}
Symbol,Company Name,Stock Price
ATRL,Attock Refinery Ltd.,171.54
AVN,Avanceon Ltd. Consolidated,78.1
BAHL,Bank AL-Habib Ltd.,54.97
CHCC,Cherat Cement Company Ltd.,126.26