CSCI 2270
Computer Science 2:
Data Structures
Fall 2003
Karl Winklmann
Thursday, September 11, 2003
These are more code fragments discussed in class.
#include <fstream>
#include <iostream>
#include <string>
...
string testFileName;
ifstream testFile;
...
cin >> testFileName;
testFile.open (testFileName.c_str ());
if (!testFile)
// for some reason the file is not available
else // successful open
{
while (testFile.peek () != EOF)
{
testFile >> x >> y >> z >> dx >> dy >> dz;
// do what needs to be done with that input
}
testFile.close ();
}
sort (canvas.elements, canvas.elements + canvas.n);
bool operator< ( const MovingObject& mo1, const MovingObject& mo2 )
{
return mo1.z > mo2.z; // yes, backwards (depending on your conventions
// about the coordinate system)
}
| © 2003 Karl Winklmann | 3:08 PM, Tuesday, December 16, 2003 |