- 0
✩
2
2 ответа:
-
- 6
Не хватает исходных данных. Файл бинарный или текстовый? Для текстового:
double x, y; fscanf("%g%g", &x, &y)Для бинарного:
fseek(...) fread(&x, sizeof(double), 1, fp) fread(&y, sizeof(double), 1, fp)Или C++:
coords.txt
1.001 -0.4565 45.2352 1235.1235 -.2315 0 1 2запускаем ./freadcpp
[1] X:1.001 Y:-0.4565 [2] X:45.2352 Y:1235.12 [3] X:-0.2315 Y:0 [4] X:1 Y:2 [5] X:1 Y:2 1.001 45.2352 -0.2315 1 1freadcpp.cc
#include <iostream> #include <vector> #include <string> #include <fstream> struct coord_t { double x; double y; }; int main() { std::vector<struct coord_t> coord; std::string s = "coords.txt"; std::fstream f; struct coord_t xy; f.open(s.c_str()); for (int i = 1; !f.eof(); ++i) { f >> xy.x; f >> xy.y; std::cout << "[" << i << "] X:" << xy.x << " Y:" << xy.y << std::endl; coord.push_back(xy); } f.close(); for (std::vector<struct coord_t>::iterator it = coord.begin(); it != coord.end(); ++it) { std::cout << it->x << std::endl; } return 0; }P.S. Причём тут слово Visual я тоже не понял.
-
- -1