well, here's some of my code, for example:
Code:
struct RangeRecord
{
// Data members
unsigned prn;
double time;
double position[3];
double pseudorange; // range measurement
double pseudorangeStdDev; // range measurement std. dev.
bool read( istream& input );
};
bool readRanges( const string& filename, vector<RangeRecord>& ranges );
int main(int argc, char* argv[] )
{
// -- Read ranges into an array -----------------------------------------
vector<RangeRecord> ranges;
if( !readRanges( config.inputFileName, ranges ) )
{
cerr << "Error!\n Unable to read ranges!\n\n";
return EXIT_FAILURE;
}
//main continues (other functions....)
//end main (main function is fine)
}
// Read a range record from a file
// Returns:
// true - input was successful
// false - input failed
//
// Parameters:
// input - input file stream that has already been opened
bool RangeRecord::read( istream& input )
{
input >> prn
>> time
>> position[0] >> position[1] >> position[2]
>> pseudorange
>> pseudorangeStdDev;
if( !input )
return false;
return true;
}
// Read the configuration from a file
//
// Returns:
// true - input was successful
// false - input failed
//
// Parameters:
// filename - Path of file containing ranges
// ranges - Array of ranges
bool readRanges( const string& filename, vector<RangeRecord>& ranges )
{
int size;
ifstream input( filename.c_str() );
if( !input )
return false;
input >> size;
ranges.resize(size); //Changes size of vector to hold records
for(int i = 0; i < size ; i++)
{
if(!ranges[i].read(input))
return false;
}
return true;
}