C++新人求解问题错误原因及修改建议
#include <iostream>
#include<fstream>
#include<cstdlib>
using namespace std;
#ifdef WIN32
#define TEST_FILE "C:\\Users\\Administrator\\Desktop\\read.txt"
#else
#define TEST_FILE "C:\\Users\\Administrator\\Desktop\\read.txt"
#endif
const int N = 2048;
struct GNSSData
{
int NO;
double Alt;
double GeopH;
double Refrac;
};
void test()
{
GNSSData gnssdata[N];
fstream FILE_OPEN_WW(TEST_FILE,ios::in);
if (!FILE_OPEN_WW)
{
cerr << "open error!" << endl;
exit(1);
}
int i = 0;
int counter = 0;
while (!FILE_OPEN_WW.eof())
{
FILE_OPEN_WW >> gnssdata[i].NO >> "\t" >> gnssdata[i].Alt >> " \t" >> gnssdata[i].GeopH >> "\t " >> gnssdata[i].Refrac;//错误 1 error C2679: 二进制“>>”: 没有找到接受“const char [2]”类型的右操作数的运算符(或没有可接受的转换)
++counter;
++i;
}
FILE_OPEN_WW.close();
for (i = 0; i < counter; i++)
{
cout << gnssdata[i].NO << "\t" << gnssdata[i].Alt << "\t" << gnssdata[i].GeopH << "\t" << gnssdata[i].Refrac << endl;
}
}
int main()
{
test();
system("pause");
return 0;
}
数据格式
B= 73.965 L= -29.457
2010 1 4 0: 4:42.000
Altitude, unit: m; Geopotential height, unit: gpm; Refractivity, unit: N
NO Alt GeopH Refrac
1 127.7539 128.0322 3.001763e+002
2 257.6292 258.1852 2.954945e+002
3 386.8093 387.6362 2.909217e+002
4 515.3259 516.4172 2.864528e+002
5 643.2098 644.5590 2.820830e+002
6 770.4980 772.0988 2.778066e+002
7 897.2189 899.0650 2.736190e+002
8 1023.3960 1025.4815 2.695166e+002
9 1149.0560 1151.3749 2.654953e+002
............
-----------------------------------------------------------------------------------------------------
求指导文件读取的正确方式(能用二维数组存储最好)