150 likes | 336 Views
COP 3530 Data Structures & Algorithms. Discussion Session 3. Outline. Input-output streams in C++ Floating point precision File manipulation Pointers in C Vector class in C++ Strings in C and C++. About me. Eyup Serdar Ayaz ayaz@cise.ufl.edu TA Office: E309 This week no office hours.
E N D
COP 3530Data Structures & Algorithms Discussion Session 3
Outline • Input-output streams in C++ • Floating point precision • File manipulation • Pointers in C • Vector class in C++ • Strings in C and C++
About me • EyupSerdarAyaz • ayaz@cise.ufl.edu • TA Office: E309 • This week no office hours
Input and output streams in C++ • Stream classes • Stream objects • Insertion (<<) and extraction (>>) operators
Floating point precision • default precision • scientific precision • fixed precision
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
Pointers in C • Reference operator (&) • Dereference operator (*) • Types of pointers • Arrays as pointers • Pointer arithmetic • Pointers to pointers • Null pointer
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
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 <cstring> • Cannot be assigned directly other than declaration • Frequently used functions: • strcpy • strcmp • strcat • strlen
String class in C++ • Strings are objects • String manipulation functions are defined in <string> • Can be directly assigned • Can be concatenated using + operator • Frequently used functions: • operator[] or at • size • copy • compare • substr • operator+= or append
References • http://www.cprogramming.com/tutorial/lesson9.html • http://www.fredosaurus.com/notes-cpp/io/readtextfile.html • http://www.cplusplus.com/reference/iostream/ • http://www.cplusplus.com/reference/iostream/manipulators/setprecision/ • http://www.cplusplus.com/reference/stl/list/sort/