c++ 读取文件字符串 并且解析
/*
"/Users/macname/Desktop/aa-1.log"
链接:https://pan.baidu.com/s/1fKB5vXDe6bYOhoslc-kr7w 密码:nb9s
*/
code:
// // main.cpp // demo // #include<iostream> #include<fstream> #include<string> #include <sstream> #include<ctime> #include<cstdlib> #include<queue> #include<cstdio> using namespace std; void initialMaze(); //任意位置的结构体 struct point { int x; int y; }; int main() { //792*675 int height=792; int width=675; //位置 int curpos[2]={337,300}; int data[width][height]; int list[height*width]; int count=0; string a; char x; ifstream file; file.open("/Users/macname/Desktop/aa-1.log",ios::in); if(!file.is_open()) return 0; string str; string sst; while(getline(file,str)) { sst+=str; } //cout<<sst<<endl; for(int i=0;i<sst.length();i++){ x=sst[i]; if(x=='[' || x==']' || x==','){ continue; }else{ a+=x; if(sst[i+1]==',' || sst[i+1]==']'){ list[count]=stoi(a); count+=1; a=""; } } } count=0; for(int i=0;i<width;i++){ for(int j=0;j<height;j++){ //cout<< list[count]<<endl; if(list[count]<25){ data[i][j]=254; }else if(list[count]<65){ data[i][j]=205; }else{ data[i][j]=0; } count+=1; } } //显示 count=0; for(int i=0;i<width;i++){ for(int j=0;j<height;j++){ //cout<< data[i][j] <<endl; count+=1; } } cout << count <<endl; return 0; }