31251 Lecture Notes - Lecture 2: Memory Management, Memory Leak, Standard Streams

46 views2 pages
cin and cout
• They are in the iostream library in the C++ Standard Library.
• Write to standard output with cout << [stuff to write] ;
• Read with cin >> [destination];
• To read a whole line: getline(cin, [variable to read in to])
• cerr also exists for errors (equivalent to System.err in Java).
File i/o
• Uses the same abstractions as cin and cout, but with a little more fiddling.
• Use the library fstream.
• Create an ofstream for writing.
• Create an ifstream for reading
Classes and Destructors
~intLinkedList().
• This is a destructor.
• This is a special method that’s run when an object has the special delete operator called
on it.
• Syntax: delete [pointer to thing to delete].
• For arrays: delete[] [array variable].
• delete is needed when we’ve created something with new.
• Otherwise the heap memory is not deallocated, and we have a memory leak.
Exceptions
• C++ can throw exceptions, just like Java.
• It has try ... catch([Exception Type] [parameter name]) .. like Java.
Queues
The (basic) Queue is the basic FIFO (first-in-first-out) data structure.
• It keeps things in order (like a list), but...
• Things can only be added to the back, and
• Things can only be taken off the front.
• Normally has an unbounded capacity.
1 | P a g e
find more resources at oneclass.com
find more resources at oneclass.com
Unlock document

This preview shows half of the first page of the document.
Unlock all 2 pages and 3 million more documents.

Already have an account? Log in

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents