Hi,
I am trying to read the file (f1.txt) which contains :
3 0
-6 0
4 0
-8 0
...
I wish to read the first number from consecutive 2 lines and process them.
Following is my code:
std::vector<int> row;
std::vector<std::vector<int> > two_node;
int main()
{
string line1, line2;
int writetofile();
ifstream myfile ("f1.txt");
if(myfile.is_open())
{
while(! myfile.eof() )
{
getline (myfile, line1);
getline (myfile, line2);
row.push_back(line[0]);
row.push_back(line[1]);
two_node.push_back(row);
writetofile();
row.clear();
}
myfile.close();
}
else cout << "Unable to open the file \n";
return 0;
}
int writetofile()
{
ofstream file1;
file1.open("f2.imp",ios::app);
file1 << row[0] << " " << row[1] << " " << 0 << "\n";
file1.close();
return 0;
}
My code is not working. I need the output in f2.imp as :
3 -6 0
4 -8 0
........
Thanks.