Download presentation
Presentation is loading. Please wait.
Published byJulie Pierce Modified over 9 years ago
1
COP 3530 Data Structures & Algorithms Discussion Session 3
2
Outline Input-output streams in C++ Floating point precision File manipulation Pointers in C Vector class in C++ Strings in C and C++
3
About me Eyup Serdar Ayaz ayaz@cise.ufl.edu ayaz@cise.ufl.edu TA Office: E309 This week no office hours
4
Input and output streams in C++ Stream classes Stream objects Insertion ( >) operators
5
Floating point precision default precision scientific precision fixed precision
6
File manipulation in C++ Include necessary header: fstream Declare an file stream: ifstream or ofstream Open the stream file Check if the file is opened Read from or write to the stream Close the stream
7
File manipulation example
8
Pointers in C Reference operator (&) Dereference operator (*) Types of pointers Arrays as pointers Pointer arithmetic Pointers to pointers Null pointer
9
Vector class in C++ An STL (Standard Template Library) container An strict sequence container i.e. An array of variable size. Similar to ArrayList of Java Defined as a template, type should be specified Most useful functions: operator[] size insert erase begin end
10
A vector example
11
Strings in C Strings are char arrays Declared as char arrays or pointers Ends with ‘\0’ or simply 0 String manipulation functions are defined in Cannot be assigned directly other than declaration Frequently used functions: strcpy strcmp strcat strlen
12
cstring example
13
String class in C++ Strings are objects String manipulation functions are defined in Can be directly assigned Can be concatenated using + operator Frequently used functions: operator[] or at size copy compare substr operator+= or append
14
C++ String example(Comparison)
15
References http://www.cprogramming.com/tutorial/lesson9.html http://www.cprogramming.com/tutorial/lesson9.html http://www.fredosaurus.com/notes- cpp/io/readtextfile.html http://www.fredosaurus.com/notes- cpp/io/readtextfile.html http://www.cplusplus.com/reference/iostream/ http://www.cplusplus.com/reference/iostream/ http://www.cplusplus.com/reference/iostream/manipulator s/setprecision/ http://www.cplusplus.com/reference/iostream/manipulator s/setprecision/ http://www.cplusplus.com/reference/stl/list/sort/ http://www.cplusplus.com/reference/stl/list/sort/
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.