我想读取如下格式的asc文件,想把前六行略过,余下的数字存入数组进行后续计算。我写的代码在下面,大致思路是全部读到vector容器里面,循环12次v1.erase(v1.begin()); 应该就吧前面的哪些元素删了吧?但是运行的时候报错
ncols 543
nrows 220
xllcorner 488469.3190918
yllcorner 3797068.373291
cellsize 2
NODATA_value -9999
-9999 -9999 -9999 -9999 -9999 -9999
0.015 0.015 0.015 0.015 0.015 0.015
0.015 0.015 0.015 0.015 0.015 0.2 0.015
0.015 0.015 0.015 0.015 0.015 0.015
#include<iostream>
#include<fstream>
#include<vector>
#include<string>
#include<sstream>
using namespace std;
void test()
{
vector<vector<string>>v1;
double array[543][220];
int i = 0, j = 0;
string lineStr;
char* end;
ifstream manning;
manning.open("C:\\Users\\lch\\Desktop\\C++\\MM\\manning.asc", ios::in);
if (!manning.is_open())
{
cout << "文件打开失败" << endl;
}
while (getline(manning, lineStr))
{
stringstream ss(lineStr);
string str;
vector<string>linearray;
while (getline(ss, str, ' '))
{
vector<vector<string>>::iterator it = v1.begin();
for (int zz = 0; zz < 12; zz++)
{
it = v1.erase(it);
}
array[i][j] = atof(const_cast<const char*> (str.c_str()));
j++;
}
i++;
}
manning.close();
for (int i = 0; i < 543; i++)
{
for (int j = 0; j < 220; j++)
{
cout << array[i][j] << endl;
}
}
}
int main()
{
test();
system("pause");
return 0;
}
这是我改写的一个代码,想通过循环删除vector容器中的第一个元素,把开头那六行删掉,把剩下从-9999开始的所有数字存到二维数组。方便后面计算,但是我在运行时提示如下错误
void _Tidy() noexcept { // free all storage
auto& _My_data = _Mypair._Myval2;
pointer& _Myfirst = _My_data._Myfirst;
pointer& _Mylast = _My_data._Mylast;
pointer& _Myend = _My_data._Myend;
_My_data._Orphan_all();
if (_Myfirst) { // destroy and deallocate old array **_引发了异常: 读取访问权限冲突。this 是 nullptr。_**
_Destroy(_Myfirst, _Mylast);
_Getal().deallocate(_Myfirst, static_cast<size_type>(_Myend - _Myfirst));
_Myfirst = pointer();
_Mylast = pointer();
_Myend = pointer();
}
}
请问大神们该怎么改?或者又什么方法能让我跳过前六行只读取后面的那些数字?