#include <iostream>
// #include <iomanip> not needed
// #include <cmath> not needed
#include <fstream>
// #include <string> not needed
usingnamespace std;
int main()
{
int d,m,s,b=0,l=0;
ifstream file("Text.txt");
if(file.is_open())
{
cout << "File has opened." << endl;}
else {cout << "File has not opened." << endl; // -------------------- move this here
return 0; // -------------------------------------------- add this to end program if file is not opened
}
file >> d;
cout << d << endl;
// --------------------------------------- Declare a loop
file >> m >> s;
cout << m << " " << s << endl;
b+=m;
l+=s;
// ------------------------------------------ end the loop
/* Eliminate this
file >> m >> s;
cout << m << " " << s << endl;
b+=m;
l+=s;
file >> m >> s;
cout << m << " " << s << endl;
b+=m;
l+=s;
*/
cout << "D=" << d << endl;
cout << "B=" << b << endl;
cout << "L=" << l << endl;
return 0;
}
I need to get two integers out of 'line', 1st integer as 1st number from a new line, and 2nd integer as numbers after the 1st number. I have already got first lines first number, dont know how to get others because of different lenght.
My text numbers:
4
3 24.5 59.0 71.7
2 45 66.2
2 34.1 45.1
4 45.2 56.4 45.1 56.2