so here are my instructions to create a while loop to open a file called ‘G:/points.dat’
This is my code so far. I'm struggling to create the for loop that reads through the file, prints them to the monitor and then using those integers as x, y points. I can understand naming the x and y parameters, but im struggling with the loop itself
#include "Window.h"
#include "Colours.h"
#include <fstream>
#include <iomanip>
#include <string>
using namespace std;
int main(int argc, char * argv[]) {
// create a new window of size 500 x 500 pixels
// the top left corner of the window is (0,0)
SPA::Window window(500,500,"My Test");
ifstream myInputFile;
string inputFileName = "G:/points,dat";
myInputFile.open(inputFileName);
int i = 0;
myInputFile >> i;
myInputFile.close();
window.show(argc,argv);
return Fl::run();
}
Open file ‘G:/points.dat’
Read in multiple pairs of numbers – ie two numbers per line until the end of the file
You should use a while loop and appropriate tests of the file state to detect the end of file
- the eof flag only gets set to true after you have tried to read at least one value beyond the end of the file.
- Each pair of numbers represents the x and y coordinates (x,y) of a point on a line to be drawn.
- Inside your loop add a point to the current line for each (x,y) value you read in