#include <iostream> #include <fstream> #include <memory.h> using namespace std; const int FULL_LOGITUDE = 180; const int FULL_LATITUDE = 90; const int THE_PRIME_MERIDIAN = 3; class World { //地图的长度 private: int width; int high; char** arr; public: World(string file) { width = 135; high = 36; char buffer[256]; ifstream ifile; ifile.open("world.txt"); arr = new char*[high]; for(int i=0; i<high; i++) { arr[i] = new char[width]; for(int j=0 ;j<width;j++){ arr[i][j]=‘+‘; } } for(int i=0;i<high;i++) { ifile.getline(buffer,256); memcpy(arr[i],buffer,width); } }; ~World(){ for(int i=0;i<high;i++){ delete []arr[i]; } delete []arr; } void Print() { for(int i =0; i<high; i++) { for(int j=0;j<width;j++){ cout<<arr[i][j]; } cout<<endl; } }; //对应x,y轴 东经是正数,西经是负数,北纬是正数,南纬是负数 void Where(double log, double lat){ int x = int ((log*width/2)/FULL_LOGITUDE); int y = int ((lat*high/2)/FULL_LATITUDE); x+=THE_PRIME_MERIDIAN; if(x<0){ x+=width; } y=high/2-y; cout<<"x y "<<x<<" "<<y<<endl; char temp = arr[y][x]; /* @ @@@ @ */ arr[y][x]=‘@‘; Print(); arr[y][x] = temp; } }; int main() { World world = World("world.txt"); //world.Print(); int x,y; cout<<"一次输入经度和纬度,东西经用正负表示,北南纬用正负表示"<<endl; cin>>x; cin>>y; world.Where(x,y); }
还有一个 世界地图字符画的txt文件
在这个地址下面 https://github.com/ggaaooppeenngg/worldPicture/blob/master/world.txt