J
Jerry
I'm new to c++, trying a simple test to read data form a txt file.
I compiled with gcc version 3.4.4 20050721 (Red Hat 3.4.4-2).
It didn't work as expected, getline() return with null string and
failed to read the left data.
Is there anything missing?
Thanks
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main( )
{ string orbfile, outfile, stemp, rinfile, teqcPltFile, rinexObsFile;
double year1, mon1, day1, hr1, min1, sec1;
double year2, mon2, day2, hr2, min2, sec2;
double cutoffAngle;
ifstream inp("cf2sky.inp");
inp >> year1 >> mon1 >> day1 >> hr1 >> min1 >> sec1;
inp >> year2 >> mon2 >> day2 >> hr2 >> min2 >> sec2;
inp >> orbfile;
getline(inp,stemp);
inp >> cutoffAngle;
inp >> rinexObsFile;
inp >> teqcPltFile;
inp.close();
cerr << year1 << mon1 << day1 << hr1 << min1 << sec1 << endl;
cerr << year2 << mon2 << day2 << hr2 << min2 << sec2 << endl;
cerr << orbfile << endl;
cerr << stemp << endl;
cerr << cutoffAngle << endl;
cerr << rinexObsFile << endl;
cerr << teqcPltFile << endl;
return 0;
}
**********************Here are output********************
2005812500
2005812700
/home/jerry/GAMIT/preproc/cf2sky/auto2240.05n
4.18086e-305
*************************************************************
********************Here are input file*********************
2005 8 12 5 0 0
2005 8 12 7 0 0
/home/jerry/GAMIT/preproc/cf2sky/auto2240.05n
P1 Pseudorange Multipath at DEQN
10
/home/jerry/GAMIT/preproc/cf2sky/deqn2240.05o
/home/jerry/GAMIT/preproc/cf2sky/deqn2240.mp1
***************************************************************
I compiled with gcc version 3.4.4 20050721 (Red Hat 3.4.4-2).
It didn't work as expected, getline() return with null string and
failed to read the left data.
Is there anything missing?
Thanks
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main( )
{ string orbfile, outfile, stemp, rinfile, teqcPltFile, rinexObsFile;
double year1, mon1, day1, hr1, min1, sec1;
double year2, mon2, day2, hr2, min2, sec2;
double cutoffAngle;
ifstream inp("cf2sky.inp");
inp >> year1 >> mon1 >> day1 >> hr1 >> min1 >> sec1;
inp >> year2 >> mon2 >> day2 >> hr2 >> min2 >> sec2;
inp >> orbfile;
getline(inp,stemp);
inp >> cutoffAngle;
inp >> rinexObsFile;
inp >> teqcPltFile;
inp.close();
cerr << year1 << mon1 << day1 << hr1 << min1 << sec1 << endl;
cerr << year2 << mon2 << day2 << hr2 << min2 << sec2 << endl;
cerr << orbfile << endl;
cerr << stemp << endl;
cerr << cutoffAngle << endl;
cerr << rinexObsFile << endl;
cerr << teqcPltFile << endl;
return 0;
}
**********************Here are output********************
2005812500
2005812700
/home/jerry/GAMIT/preproc/cf2sky/auto2240.05n
4.18086e-305
*************************************************************
********************Here are input file*********************
2005 8 12 5 0 0
2005 8 12 7 0 0
/home/jerry/GAMIT/preproc/cf2sky/auto2240.05n
P1 Pseudorange Multipath at DEQN
10
/home/jerry/GAMIT/preproc/cf2sky/deqn2240.05o
/home/jerry/GAMIT/preproc/cf2sky/deqn2240.mp1
***************************************************************