#include<fstream>
#include<vector>
#include<string>
#include<sstream>
#include<string.h>
using namespace std;
void test() {
ifstream manning("manning.asc", ios::in);
if (!manning.is_open()) {
cout << "文件打开失败" << endl;
exit(-1);
}
std::string name;
int ncols, nrows, cellsize, NODATA_value;
double xllcorner, yllcorner;
manning >> name >> ncols;
manning >> name >> nrows;
manning >> name >> xllcorner;
manning >> name >> yllcorner;
manning >> name >> cellsize;
manning >> name >> NODATA_value;
double **array = new double *;
for(int i = 0; i < nrows; ++i) {
array = new double;
}
std::string line;
for(int y = 0; y < nrows; ++y) {
getline(manning, line);
std::stringstream ss(line);
for(int x = 0; x < ncols; ++x) {
ss >> array;
}
}
std::cout << name <<" " << ncols << std::endl;
std::cout << name << " " << nrows << std::endl;
std::cout << name << " " << xllcorner << std::endl;
std::cout << name << " " << yllcorner << std::endl;
std::cout << name << " " << cellsize << std::endl;
std::cout << name << " " << NODATA_value << std::endl;
/*for(int y = 0; y < nrows; ++y) {
for(int x = 0; x < ncols; ++x) {
std::cout << array << " ";
}
std::cout << std::endl;
}*/
for(int i = 0; i < nrows; ++i) {
delete[] array;
}
delete[] array;
manning.close();
}
#if 0
void test()
{
double** array = new double* ;//array1 用来存储从gauges中读到的数据。
int i = 0, j = 0, line = 0;
for (i = 0; i < 543; i++)
{
array = new double;
}
//double array;
//memset(array, 0, sizeof(array));
string lineStr;
//char* end;
ifstream manning;
manning.open("manning.asc", ios::in);
if (!manning.is_open())
{
cout << "文件打开失败" << endl;
exit(-1);
}
/*i = 0;
while (getline(manning, lineStr))
{
if (++line <= 6)
continue;
stringstream ss(lineStr);
string str;
j = 0;
while (getline(ss, str, ' '))
{
//array = atof(const_cast<const char*> (str.c_str()));
array = atof(str.c_str());
j++;
}
i++;
} */
i = 0;
while (getline(manning, lineStr))
{
if (++line <= 6)
continue;
stringstream ss(lineStr);
j = 0;
while( ss >> array)
;
i++;
}
manning.close();
for (int i = 0; i < 543; i++)
{
for (int j = 0; j < 220; j++)
{
cout << array << " ";
}
cout << endl;
}
for (i = 0; i < 543; i++)
{
delete[] array;
}
delete[] array;
}
#endif
int main()
{
test();
return 0;
}
$ ./main
ncols 543
nrows 220
xllcorner 488469
yllcorner 3.79707e+06
cellsize 2
NODATA_value -9999
$ ncols 543
nrows 220
xllcorner 488469.3190918
yllcorner 3797068.373291
cellsize 2
NODATA_value-9999
5W的数据不算大,普通电脑跑应该没问题。 人造人 发表于 2020-4-29 00:31
https://s1.ax1x.com/2020/04/29/JHu1eK.png
你好,冒昧打扰,请问存这些数据的数组,我想判断数组中第一列的每一个数是不是50的整数倍。直接写
array % 50 == 0 这种判断条件不行,我搜了一下 取余必须是整数,请问有什么其他的好的办法吗?数组定义是double,里面的数字也有整有零的,可能是1, 32.55, 50,100.088这种的 超级卡布达 发表于 2020-4-29 22:36
你好,冒昧打扰,请问存这些数据的数组,我想判断数组中第一列的每一个数是不是50的整数倍。直接写
...
https://www.baidu.com/s?wd=浮点数取余&pn=0&oq=浮点数取余&tn=48020221_10_hao_pg&ie=utf-8&rsv_idx=1&rsv_pq=99562fbe00041e21&rsv_t=51bdIOgBloxfHa2L%2FcwNooxLXsNZxALy0ASJUR6IXEf2kxgdzj4Xd5guDg9UTh2lYT5Tdf8Roj7q
https://zhidao.baidu.com/question/314258298.html?sort=11&rn=5&pn=0#wgt-answers 人造人 发表于 2020-4-29 23:17
这样呀,好的。多谢多谢{:5_91:}
页:
1
[2]