c++ - Reading data from a file -
I am doing an exercise where I place coordinates in a .txt file called Maidata, and then that file Read it back from. However, I'm having trouble reading it.
Code:
#include "std_lib_facilities.h" // Classes ---------- ----------- --------------------------------------- ---------- structure Point {point (int a, int b): x (a), y (b) {}; Point () {}} int x; Int y;}; // Main----------------------------------------------- - ------------------------ int main () {vector & lieutenant; Point & gt; Basic issue, vector & lt; Point & gt; Processed_points; Cout & lt; & Lt; "Please enter 7 coordinate pairs. \ N"; Int x, y; While (cin> x> x>> y) {if (x == -1; y == -1) break; Original_punes Push_back (point (x, y));} cout & lt; & Lt; "Please enter the file to send the digits. \ N"; String name; Cin & gt; & Gt; Name; Offstream ost (name.c_str ()); If (! Ost) error ("can not open output file", name); For (Int i = 0; I & lt; Original_ line size (); ++ i) Ost & lt; & Lt; Basic_point [i] .x > x>> y) processed_points.push_back (dot (x, y)); For (int i = 0; i & lt; processed pps. (); ++ i) COAT & lt; & Lt; Processed_points [i] .x & lt; & Lt; ',' & Lt; & Lt; Processed_points [i]. & Lt; & Lt; Endl; Keep_window_open (); }
To see if the data is being read from the file, I am putting it back in processed point vectors, but when I run the program and enter the digits It does not have any points output from the processed points vector. I think the problem is in ... ...
while (IST>> x>> y
And this is not the right way to read from any file, any help would be appreciated, thanks.
,
you are leaving the line
That is what is on your way, because you are not reading it back! Either use one place instead of that comma, or, read it back ...
Comments
Post a Comment