Thanks all! it was really helpful. I am a noob.
@laserlight : I have changed my code as follows, but i don't know how do this -->
Then, use the return value of getline, not good(), to control the inner loop.
can you explain me in more details.
New code:
Code:
// reading a text file
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main () {
string line;
int i,j,c;
int Ncoil, Ntank;
int **Tmin, **Tmax;
char str[256];
cout << "Number of coils to be cleaned: ";
cin >> Ncoil;
cout << "Number of tanks: ";
cin >> Ntank;
Tmin = new int *[Ncoil];
ifstream myfile ("Tmin.txt");
if (myfile.is_open())
{
for (int i = 0; i <= Ncoil; ++i)
{
Tmin[i] = new int[Ntank];
for(int j = 0; j <= Ntank; ++j)
{
getline(myfile, line, ' ');
while (???????)
{
c = atoi(line.c_str());
Tmin[i][j] = c;
cout<< Tmin[i][j]<<endl;
}
}
}
myfile.close();
}
else cout << "Unable to open Tmin file";
return 0;
}