hi i need to read x,y coordinates in text file using c++
the name of file is input.txt which is ,
please help me the following code was did not work. any other code is appretiated
the name of file is input.txt which is ,
Code:
x y 232.1,753.7 100.5,981.6 96.2,992.9 148.7,953.2 197.2,999.3 249.9,998.6 261.7,975.9 262.4,905.8 334.9,980.8 371.6,979.4 396.7,996.3 405.1,995 565.5,766 459.4,988.5 474.4,994.6 594.6,996.8 604,987.3 612.8,877.3 664.1,992.6
Code:
#include <iostream>
#include <fstream>
using namespace std
struct monsters_struct {
int x, y;
};
int main()
{ monsters_struct monsters[100]; //Create an array "monsters" as type "monsters_struct"
ifstream inData("input.txt");
for (int i=0; i<20; i++) {
inData >> monsters[i].x >> monsters[i].y; //Read x and y coordinates at position i
cout << monsters[i].x << " " << monsters[i].y << endl; //Output the x and y coordinates read above
}
inData.close();
return 0;
}
Comment