Container Classes & Exception Handling

Container Classes & Exception Handling

Passing Streams to Functions http://cs.mst.edu Passing Streams to Functions One Rule: always pass a stream as a reference http://cs.mst.edu file: fileopen.h // Pre: template parameter T must be either ifstream or ofstream type. template

void fileopen (T & filestr, const string promptpart) { const int MAX_TRIES = 5; int count = 0; string filename; cout<>filename; filestr.open(filename.c_str()); while (!filestr) { filestr.clear(); // may be necessary on your platform cout<>filename; filestr.open(filename.c_str());

count++; if (count > MAX_TRIES) { cout< #include fileopen.h int main() {

ifstream in; fileopen(in, input); http://cs.mst.edu Operator Overloading ostream& operator << (ostream & out, const point & p) { out << ( << p.m_X << , << p.m_Y << ); return out; } http://cs.mst.edu Operator Overloading ostream& operator << (ostream & out, const point & p)

{ out << ( << p.m_X << , << p.m_Y << ); return out; } // example 1 point p1, p2; cout << p1; cout << p1 << " << p2; http://cs.mst.edu Operator Overloading ostream& operator { out << ( << return out;

} // example 1 point p1, p2; cout << p1; cout << p1 << // example 2 ofstream fout; fout << p1; fout << p1 << << (ostream & out, const point & p) p.m_X << , << p.m_Y << ); << p2; << p2;

http://cs.mst.edu Chaining // example 1 cout << p1 << << p2; ... ostream& operator << (ostream & out, const point & p) { out << ( << p.m_X << , << p.m_Y << ); return out; } Stream Processing...

http://cs.mst.edu Chaining // example 1 cout << p1 << << p2; ... ostream& operator << (ostream & out, const point & p) { out << ( << p.m_X << , << p.m_Y << ); return out; } Stream Processing... cout << p1

http://cs.mst.edu Chaining // example 1 cout << p1 << << p2; ... ostream& operator << (ostream & out, const point & p) { out << ( << p.m_X << , << p.m_Y << ); return out; } Stream Processing... cout << p1 executes overloaded operator<<

http://cs.mst.edu Chaining // example 1 cout << p1 << << p2; ... ostream& operator << (ostream & out, const point & p) { out << ( << p.m_X << , << p.m_Y << ); return out; } Stream Processing... cout << p1

executes overloaded operator<< returns cout with the points data added to the stream http://cs.mst.edu Chaining // example 1 cout << p1 << << p2; ... ostream& operator << (ostream & out, const point & p) { out << ( << p.m_X << , << p.m_Y << ); return out; }

Stream Processing... cout << p1 executes overloaded operator<< returns cout with the points data added to the stream cout << http://cs.mst.edu Chaining // example 1 cout << p1 << << p2; ... ostream& operator << (ostream & out, const point & p) { out << ( << p.m_X << , << p.m_Y << );

return out; } System Processing... cout << p1 executes overloaded operator<< returns cout with the points data added to the stream cout << returns cout with the space added to the stream http://cs.mst.edu Chaining // example 1 cout << p1 << << p2;

... ostream& operator << (ostream & out, const point & p) { out << ( << p.m_X << , << p.m_Y << ); return out; } Stream Processing... cout << p1 executes overloaded operator<< returns cout with the points data added to the stream cout << returns cout with the space added to the stream cout << p2 http://cs.mst.edu

Chaining // example 1 cout << p1 << << p2; ... ostream& operator << (ostream & out, const point & p) { out << ( << p.m_X << , << p.m_Y << ); return out; } Stream Processing... cout << p1 executes overloaded operator<< returns cout with the points data added to the stream

cout << returns cout with the space added to the stream cout << p2 executes overloaded operator<< http://cs.mst.edu Chaining // example 1 cout << p1 << << p2; ... ostream& operator << (ostream & out, const point & p) { out << ( << p.m_X << , << p.m_Y << ); return out;

} Stream Processing... cout << p1 executes overloaded operator<< returns cout with the points data added to the stream cout << returns cout with the space added to the stream cout << p2 executes overloaded operator<< returns cout with the points data added to the stream http://cs.mst.edu Final Note iostream and fstream are of the same family

getline, ignore, get, putback, etc are all available for filestreams as well! ifstream fin; char input; fin.open(input.dat); while (in.get(input)) { process_data(input); http://cs.mst.edu End of Session http://cs.mst.edu

Recently Viewed Presentations

  • Valuation 5e - Chapter 2 - Finance Department

    Valuation 5e - Chapter 2 - Finance Department

    value driver (KVD) formula. The key value driver formula is superior to alternative methodologies because it is cash flow based and links cash flow to growth and ROIC. Economic-profit model. The economic-profit model leads to results consistent with the KVD...
  • The Knee

    The Knee

    Posterior Cruciate Ligament (PCL) Purpose: Keep the Tibia from translating posteriorly (bkwrds) 120% to 150% wider than ACL; is Primary stabilizer of knee ... Medial Meniscus - more of a crescent shape, wider posteriorly than anteriorly. Lateral Meniscus - more...
  • MOST FREQUENTLY CITED SERIOUS VIOLATIONS CONSTRUC TION INDUSTRY

    MOST FREQUENTLY CITED SERIOUS VIOLATIONS CONSTRUC TION INDUSTRY

    N. ot Extended . 3 feet . Above Landing. Fall Protection - Unprotected Sides & Edges. Fall Protection - Training. Eye and Face Protection. Head Protection. Scaffolds - Fall Protection. Aerial lifts - Fall Protection. Safe Access.
  • CREATING CARE-CONNECTED COMMUNITIES West Michigan Health Forum October

    CREATING CARE-CONNECTED COMMUNITIES West Michigan Health Forum October

    Interoperability is a means, not an end goal. No healthcare stakeholder is a self-contained island. A consolidated longitudinal health record is vital to patient care delivery and management
  • Fast and Accurate Content-based Semantic Search in 100M

    Fast and Accurate Content-based Semantic Search in 100M

    Indexing textual features like ASR and OCR is well studied. Indexing semantic concepts is not well understood. Existing methods index the raw detection score of semantic concepts by dense matrices [Mazloom et al. 2014][Wu et al. 2014][Lee et al. 2014]
  • Earth&#x27;s Layers

    Earth's Layers

    CRUST:. Is the outermost layer on the earth. (EGG SHELL) Thickness varies. Under mountains it can be as thick as 60 km and less than 5 km under the ocean.
  • ClearLinkTM Universal DAS Interface Tray (UDITTM)

    ClearLinkTM Universal DAS Interface Tray (UDITTM)

    C Squared Site Portal. AT&T NetCool. Westell/Kentrox Optima. Provides alarm collection and periodic synchronization in the event of an outage or loss of connectivity. Provides 7 days of key performance indicator (KPI) retention across all remote products . The minimum...
  • Literary Terms - Staunton River High School

    Literary Terms - Staunton River High School

    The following is an example of which literary term? "Learnèd Faustus, to find the secrets of astronomyGraven in the book of Jove's high firmament, Did mount him up to scale Olympus' top,Where, sitting in a chariot burning bright" Allusion. Archetype....