首先采用QSGS方法生成了一个文件,现在想只读取这个文件中的数据并把它放在一个数组中,每行的第一个数是x,第二个数是y,第三个数是z。以用于后续的计算。不知如何实现。下面有已有的代码,但是读取不了。
for (m = 1; m < 11; m++)
{
ostringstream os;
string s_head = "./2D_";
os << m;
string s_tail = ".dat";
string s = s_head + os.str() + s_tail;
s = ("C:\\特征\\QSGS_%d.dat", m);
char* c = const_cast<char*>(s.c_str()); //指针变量
ifstream ifs(c, ios::in); //以输入的方式打开文件,file的名称是ifs
if (!ifs)
{
cout << "no data" << endl;
system("pause");
exit(-1);
}
int head = 1;
string line;
while (getline(ifs, line))// line中不包括每行的换行符
{
double x, y, p;
int i, j;
istringstream is(line);
if (head <= 3)
{
head++;
continue;
}
is >> x >> y >> p;
i = int(x);
j = int(y);
arrgrid[i][j] = p;
}
outputQSGS(m);
}