ifstream infile;
infile.open("NongTrai.in.txt");
int in[4];
int N, x, y, l;
int file_limit = 0;
string line1, lines;
if (infile.is_open())
{
while (! infile.eof())
{
getline (infile, line1);
stringstream ss(line1);
ss >> N;
for (int i = 0; i < 4; i++)
{
getline (infile, lines);
stringstream ss;
ss >> lines;
lines = in[i];
}
x = in[0];
y = in[2];
l = in[4];
}
}
infile.close();
I'm trying to write a program to read the content. The first number will be read first and assigned to N. The following lines containing 3 numbers will be read and assigned to x, y, l respectively. But looks like I wrote the code wrongly. I haven't compile it since it's on my homework and I haven't finish the rest.
Can anyone help me with this?
Thank you!
if ( getline (infile, line1) ) { // do we read the first line?
stringstream ss(line1);
if ( ss >> N ) { // does it parse as an integer?
for (int i = 0; i < N; i++) {
if ( getline (infile, line1) ) { // read N more lines
stringstream ss(line1);
if ( ss >> x >> y >> l ) { // can we extract 3 integers?
}
}
}
}
}