STL and Example.

Slides:



Advertisements
Similar presentations
Files Used to transfer data to and from disk. Opening an Output File Stream #include // File stream library. ofstream outfile;// Declare file stream variable.
Advertisements

Brown Bag #2 Advanced C++. Topics  Templates  Standard Template Library (STL)  Pointers and Smart Pointers  Exceptions  Lambda Expressions  Tips.
Vectors, lists and queues
. STL: C++ Standard Library (continued). STL Iterators u Iterators are allow to traverse sequences u Methods  operator*  operator->  operator++, and.
Multimaps. Resources -- web For each new class, browse its methods These sites are richly linked, and contain indexes, examples, documents and other resources.
CS 1620 File I/O. So far this semester all input has been from keyboard all output has been to computer screen these are just two examples of where to.
1 Lecture 31 Handling Selected Topics Again!! File I/O Special Lectures.
Streams, Files. 2 Stream Stream is a sequence of bytes Input stream In input operations, the bytes are transferred from a device to the main memory Output.
C++ How to Program, 8/e © by Pearson Education, Inc. All Rights Reserved.
COP 3530 Data Structures & Algorithms Discussion Session 3.
An Introduction to STL. The C++ Standard Template Libraries  In 1990, Alex Stepanov and Meng Lee of Hewlett Packard Laboratories extended C++ with a.
© Glenn Rowe AC Lab 3 An adventure game.
 2003 Prentice Hall, Inc. All rights reserved.m ECE 2552 Dr. Këpuska based on Dr. S. Kozaitis Summer Chapter 15 - Class string and String Stream.
Ticket Booth Base Level 3 1. In the completed program, the ticket seller will: Select a venue from a menu of all venues. Select a show from a menu of.
1 Chapter 1 C++ Templates Sections 1.6 and Templates Type-independent patterns that can work with multiple data types –Generic programming –Code.
Fall 2015CISC/CMPE320 - Prof. McLeod1 CISC/CMPE320 Managers and “mentors” identified on projects page. All member accounts created and projects populated.
Chapter 3: Input/Output. Objectives In this chapter, you will: – Learn what a stream is and examine input and output streams – Explore how to read data.
Input/Output CSci 588: Data Structures, Algorithms and Software Design Fall 2011 All material not from online sources copyright © Travis Desell, 2011
A recap of the STL and more containers Plus an intro to string and file input and output! Lecture 8.
Declaring fstream Objects An istream object named cin connects program and keyboard An ostream object named cout connects the program and the screen These.
Copyright © 2006 Pearson Addison-Wesley. All rights reserved Today’s Lecture  I/O Streams  Console I/O  File I/O  Tools for File I/O  Sequential.
File I/O in C++ I. Using Input/Output Files A computer file is stored on a secondary storage device (e.g., disk); is permanent; can be used to provide.
Streams and IO  Streams are pipe like constructors used for providing IO.  When a programmer needs to handle input from or output to external entities,then.
Computer Programming in C++ 黃鐘揚 教授 Prof. Chung-Yang (Ric) Huang Department of Electrical Engineering National Taiwan University 2007/06/26.
Computer Programming II Lecture 9. Files Processing - We have been using the iostream standard library, which provides cin and cout methods for reading.
1 Chapter 12 Classes and Abstraction. 2 Chapter 12 Topics Meaning of an Abstract Data Type Declaring and Using a class Data Type Using Separate Specification.
CS212: Object Oriented Analysis and Design
“Generic Programming” ECE 297
Chapter 12 Classes and Abstraction
C++ CSCE 343.
ifstreams and ofstreams
File Processing in C++ Data is stored in files so that it may be retrieved for processing when needed.
Vectors of Vectors Representing Objects with Two Dimensions.
Lecture 7-2 : STL Iterators
CS3340 – OOP and C++ L. Grewe.
C++ Standard Library.
Standard Template Library (STL)
CSC 113: Computer Programming (Theory = 03, Lab = 01)
Copyright © 2003 Pearson Education, Inc.
Parallel Arrays Parallel array =>Two or more arrays with the same number of elements used for storing related information about a collection of data. Example:
The C++ Algorithm Libraries
Input and Output Chapter 3.
Lecture 7-2 : STL Iterators
Today’s Learning Objective
Vectors.
Programming with Data Files
Today’s Lecture I/O Streams Tools for File I/O
when need to keep permanently
الوحدة الرابعة البرمجة وصياغة حل المسائل البرمجة وأهميتها أهداف الدرس الأول مفهوم البرمجة. الفرق بين المبرمج ومستخدم البرنامج. الحاجة إلى البرامج.
Strings and Streams Professor Hugh C. Lauer CS-2303, System Programming Concepts (Slides include materials from The C Programming Language, 2nd edition,
C++ File Structure and Intro to the STL
STL and Example.
Standard Template Library Model
Standard Input/Output Stream
File Processing in C++ Data is stored in files so that it may be retrieved for processing when needed.
Chapter 3 Input output.
CS150 Introduction to Computer Science 1
File I/O.
Standard Template Library (STL)
Lecture 8-2 : STL Iterators and Algorithms
Vectors of Vectors Representing Objects with Two Dimensions.
CHAPTER 4 File Processing.
Reading from and Writing to Files
Reading Data From and Writing Data To Text Files
C++ File Structure and Intro to the STL
Information.
Today’s Objectives 28-Jun-2006 Announcements
Standard C++ Library Part II.
An Introduction to STL.
Reading from and Writing to Files
Presentation transcript:

STL and Example

Things start doing Get C++ (Xcode/Visual Studio/gcc) Make a helloworld.cpp program and build it.

C++ Libraries – I/O <iostream> cout << "thing to print"; Prints all the fundamental types Prints string variables Can be extended to print other types cin >> variable; Reads input from standard input Parses all fundamental types Spaces separate different inputs Will read words into string variables White space separates inputs and input is read with enter

C++ STL The Standard Template Library C++ library parameterized by types similar to Java generics Containers Iterators Algorithms Functions

Review <vector> Declaration: std::vector<T>vec = {initializer list} Access and modify: vec[index] = value Assignment of whole array: new_vec = vec Find size: vec.size() Extend: vec.push_back(val)

C++ Libraries – Dictionary or Associative Array Take two types first key and second is value. <key,value> Use as an array indexed by key values. <map> Whole container can be accessed in key order O(log n) for most operations <unordered_map> Accessing the whole container is possible but the order is not defined O(1) expected for most operations

<map> Declaration: std::map<T1,T2>my_map Access and modify: my_map[index] = value Assignment of whole array: new_map = my_map Find size: my_map.size() Find: my_map.find(key) Returns an iterator to a pair <key,value>

STL iterators and pair Iterators STL pair Acts like a pointer access the value with * or -> as with a pointer Used to interact with STL containers STL pair Two types <T1,T2> Access through public member variables first and second

Filestreams ofstream – Write to a file ifstream – Read from a file fstream – Read and write from a file Open the file fstream.open(filename) Close the file fstream.close()

Gradebook