Last Updated: July 7, 2005.
My notes here are very sketchy since I started the web stuff after I finished with most of my C++.
- To unmangle names c++filt // in the same dir as CC
- Example of reading data with streams:
#include <unistd.h> #include <iostream.h> #include <fstream.h> #include <stdlib.h> int main (int argc, char **argv) { cerr.precision(1); cerr.setf(ios::showpoint | ios::right |ios::fixed); int first_time=1; if(argc !=2) { cerr << "usage " << argv[0] << ": <sm4 filename>" << endl; exit(1); } ifstream myInputFile(argv[1], ios::in ); if (!myInputFile) { cerr << "file " << argv[1] << " cannot be opened for reading." << endl; return(2); } else cerr << "file " << argv[1] << " opened for reading." << endl; // start reading double x,y,z,a; double xmin,xmax,ymin,ymax,zmin,zmax,amin,amax; int line_count=0; while ( ! myInputFile.eof() ) { myInputFile >> x; myInputFile >> y; myInputFile >> z; myInputFile >> a; line_count++; if(!(line_count % 50000)) cerr << "."; if(first_time) { xmin = xmax = x; ymin = ymax = y; zmin = zmax = z; amin = amax = a; first_time =0; } else { if (x > xmax) xmax = x; if (x < xmin) xmin = x; if (y > ymax) ymax = y; if (y < ymin) ymin = y; if (z > zmax) zmax = z; if (z < zmin) zmin = z; if (a > amax) amax = a; if (a < amin) amin = a; } } cerr << endl; cerr << "Min x, " << xmin << " Max X, " << xmax << endl; cerr << "Min y, " << ymin << " Max Y, " << ymax << endl; cerr << "Min z, " << zmin << " Max Z, " << zmax << endl; cerr << "Min attribute, " << amin << " Max Attribue, " << amax << endl; cerr << "number of lines " << line_count << endl; return(0); }
- A routine to open an output stream:
bool GridObject::writeSM4(char *filename) { ofstream outFile(filename, ios::out ); if (!outFile) { cerr << "file " << filename << " cannot be opened for writing." << endl; return(false); } else { cerr << "file " << filename << " opened for writing." << endl; outFile.unsetf(ios::left); outFile.width(12); outFile.precision(1); outFile.setf(ios::showpoint | ios::right |ios::fixed); // outFile.setf ( ios::internal | ios::showpoint | ios::right | ios::fixed ); }