I'm trying to find a way to read a .txt file and take each line of it and store it in a variable to manipulate each section later. The text file looks like this,
900 900 <- display size
3 <- number of sides
400 0 <- point 1
746 600 <- point 2
54 600 <- point 3
Each line has the coordinates of a point.
Right now I just have a simple reader set up like this,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#include <iostream>
#include <fstream>
usingnamespace std;
int main (int argc, char* argv[]) {
string line;
string filename = "triangle.txt";
ifstream reader(filename);
while (getline(reader,line)) {
cout << line << endl;
}
reader.close();
return 0;
}
I will need to be able to find the midpoint between point 1 and 2, 2 and 3, and 3 and 1. I don't know if I'm on track for what I want to do. Thanks.