file input and output

So I am trying to create a program that reads a series of files and creates a graph plotting points from the file. So far my code looks a little something like this -

include <iostream>
include "ccc_x11.h"
include "ccc_shap.h"
include "ccc_win.h"
include <fstream>
using namespace std ;
int ccc_win_main() {
cwin.coord(-10, -10, 10, 10);

 // initiating variables for the first input file
double x1_1, x2_1, x3_1, x4_1, x5_1, x6_1, x7_1, x8_1, x9_1, x10_1, x11_1, x12_1, x13_1;
double y1_1, y2_1, y3_1, y4_1, y5_1, y6_1, y7_1, y8_1, y9_1, y10_1, y11_1, y12_1, y13_1;


ifstream fin("input_1.txt");


//assigning numbers from first file to variables
fin >> x1_1 >> x2_1 >> x3_1 >> x4_1 >> x5_1 >> x6_1 >> x7_1 >> x8_1 >> x9_1 >> x10_1 >> x11_1 >> x12_1 >> x13_1 >> y1_1 >> y2_1 >> y3_1 >> y4_1 >> y5_1 >> y6_1 >> y7_1 >> y8_1 >> y9_1 >> y10_1 >> y11_1 >> y12_1 >> y13_1;


//Now creating points from the inputs from the first file

Point p1_1 (x1_1 , y1_1);
Point p2_1 (x2_1 , y2_1);
Point p3_1 (x3_1 , y3_1);
Point p4_1 (x4_1 , y4_1);
Point p5_1 (x5_1 , y5_1);
Point p6_1 (x6_1 , y6_1);
Point p7_1 (x7_1 , y7_1);
Point p8_1 (x8_1 , y8_1);
Point p9_1 (x9_1 , y9_1);
Point p10_1 (x10_1 , y10_1);
Point p11_1 (x11_1 , y11_1);
Point p12_1 (x12_1 , y12_1);
Point p13_1 (x13_1 , y13_1);

// creating lines from file one

Line L1_1(p1_1 , p2_1);
Line L2_1(p2_1 , p3_1);
Line L3_1(p3_1 , p4_1);
Line L4_1(p4_1 , p5_1);
Line L5_1(p5_1 , p6_1);
Line L6_1(p6_1 , p7_1);
Line L7_1(p7_1 , p8_1);
Line L8_1(p8_1 , p9_1);
Line L9_1(p9_1 , p10_1);
Line L10_1(p10_1 , p11_1);
Line L11_1(p11_1 , p12_1);
Line L12_1(p12_1 , p13_1);

//displaying lines from the first file

cwin << L1_1 << L2_1 << L3_1 << L4_1 << L5_1 << L6_1 << L7_1 << L8_1 << L9_1 << L10_1 << L11_1 << L12_1;


//closing and clearing the first file
fin.close();
fin.clear();

however when I run the program nothing happens. I think it has to do with the way I set up my files, which looks a little something like this -

-9 -9 -9 -9 -9 -9 -7 -7 -6 -6 -5 -5 -4 6 3 1 -1 -3 -6 5 -5 4 -4 2 -2 0

the first thirteen numbers are the x values of the points, and the last thirteen are the y values of the points. Is there any other way to have my program read the file and display the given points?? I would use getline() however that would make my point into a string, and I dont really know how to convert a string to a double before putting the variable into a point.
Last edited on
http://www.cplusplus.com/doc/tutorial/control/ (loops)

> include "ccc_win.h"
¿what's that?
it's a custom header file for outputting points lines and circles to an XQuartz window
Topic archived. No new replies allowed.