Re: Reading file into array
Are you accessing "cells that don't have a value" ?
The following is how you would loop thru this structure:
Code:
for (int i=0; i<allData.size(); ++i)
{
for (int j=0; j<allData[i].size(); ++j)
{
cout << allData[i][j] << " ";
}
cout << "\n";
}
Re: Reading file into array
Quote:
Originally Posted by
Philip Nicoletti
Are you accessing "cells that don't have a value" ?
The following is how you would loop thru this structure:
Code:
for (int i=0; i<allData.size(); ++i)
{
for (int j=0; j<allData[i].size(); ++j)
{
cout << allData[i][j] << " ";
}
cout << "\n";
}
Thanks for reply, i modified your code to suit my purpose and now i want to access a specific column in a specific row. how to do it? because i want to read and analyze the 3rd column values.
Code:
int currentPosition=1;
for (int i=0;i<allData.size();i++){
for (int j =0;j<allData[i].size();j++){
if (allData[i][0]==currentPosition){
for (;j<allData[i].size();j++){
cout << "" << allData[i][j] << '\t';
}
cout << "" << endl;
}
}
}
}
Thanks in advance
Re: Reading file into array
Is this what you want ?
Code:
int column = 2; // 0-based (so 3rd column)
for (int i=0; i<allData.size(); ++i)
{
cout << "row = " << i << " : ";
if (column < allData[i].size() )
{
cout << allData[i][column] << "\n";
}
else
{
cout << "column does not exist for this row\n";
}
cout << "\n";
}
Re: Reading file into array
Quote:
Originally Posted by
Philip Nicoletti
Is this what you want ?
Code:
int column = 2; // 0-based (so 3rd column)
for (int i=0; i<allData.size(); ++i)
{
cout << "row = " << i << " : ";
if (column < allData[i].size() )
{
cout << allData[i][column] << "\n";
}
else
{
cout << "column does not exist for this row\n";
}
cout << "\n";
}
Thank Philip Nicoletti your help was very fruitful, i modified it for my purpose
thumb up to you
Regards,
Ewa