#include <cstdio>
#include <fstream>
#include <iostream>
#include <vector>
using namespace std;
vector <int> vec;
void Read(char *filename, int x)
{
ifstream obj_read;
obj_read.open(filename, ios::in);
string s;
while(!obj_read.eof())
{
getline(obj_read, s);
if(!s.empty())
{
char *pStart = (char *)s.c_str();
char *p;
int val;
p = pStart;
sscanf(p, "%d", &val);
if(val == x)
{
p = pStart;
while(*p!=',')
{
p++;
}
p++;
vec.clear();
while(*p)
{
while(!(*p>='0' && *p<='9'))
{
p++;
}
sscanf(p, "%d", &val);
vec.push_back(val);
while(*p>='0' && *p<='9')
{
p++;
}
}
break;
}
}
}
obj_read.close();
}
int main()
{
Read("data.txt", 16);
int i;
for(i=0;i<vec.size();i++)
{
cout << "vec[" << i << "] = " << vec[i] << endl;
}
return 0;
}
追问这个函数里的参数只定义了坐标的x位置吧, 在main函数里对于16,0和16,16这种坐标就会出现问题了吧.
追答你就不能举一反三 改一改?,收个税
本回答被提问者和网友采纳