|
发表于 2020-10-21 16:54:28
|
显示全部楼层
本楼为最佳答案
- #include <vector>
- #include <fstream>
- #include <iostream.h>
- typedef struct tagCoordinate
- {
- int x;
- int y;
-
- tagCoordinate(int _x,int _y)
- {
- x = _x;
- y = _y;
- }
- }COOR, *LPCOOR;
- using namespace std;
- int main(void)
- {
- vector<COOR> vcr;
- for(int i = 0 ; i < 10 ; i ++)
- {
- vcr.push_back(COOR(i * 2 + 1, i * 3 + 2));
- }
- ofstream fWrite("e:\\snake.dat",ios::out);
- typedef std::vector<COOR>::iterator VI;
- for(VI vi = vcr.begin() ; vi != vcr.end() ; vi++)
- {
- fWrite << vi->x << ' ' << vi->y << ' ';
- }
-
- fWrite.close();
- ifstream fRead("e:\\snake.dat",ios::in);
-
- COOR cr(0,0);
- while(!fRead.eof())
- {
- fRead >> cr.x >> cr.y;
- cout << cr.x << ',' << cr.y << endl;
- }
- return 0;
- }
复制代码 |
|