Lecture3 - CS213: C++ Programming Lecture #3: Library Types...

Info iconThis preview shows pages 1–9. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CS213: C++ Programming Lecture #3: Library Types Chapter 3 What We Will Cover Today Agenda:- namespaces- string type- vector type- iterators- bitset type Intro to Namespaces So far, our example programs have looked something like this: #include <iostream> int main(int argc, char *argv) { std::cout << Hello World! << std::endl; return 0; } What does the std:: mean? In this case, it refers to a namespace . Intro to Namespaces A namespace is similar to a package in Java. It provides an additional name to any symbol to help keep it unique. All standard C++ library functions are in a namespace called std . To use them, we must preFx the function name with std:: Hence when we see std::cout, it really means call the function cout() deFned in the std namespace. Intro to Namespaces However, this can be cumbersome. Prefxing each Function call with std:: can clutter up code. A solution is to utilize some additional syntax, like so: #include <iostream> using std::cout; using std::endl; int main(int argc, char *argv) { cout << Hello World! << endl; } Intro to Namespaces In utilizing the using directive, we can specify which functions in the std namespace we want to use in this Fle Then, all we have to do in our code is call the function in the namespace by its simple name-- without including the namespace information. This allows for cleaner, simpler code. There is another form of syntax which helps us achieve the same goal. Consider the following... Intro to Namespaces A different way... #include <iostream> using namespace std; int main(int argc, char *argv) { cout << Hello World! << endl; return 0; } This different form of using tells the compiler that any undeFned symbol should be looked for in the std namespace before generating a symbol not deFned type error. Intro to Namespaces In fact, many default C++ projects generated by corresponding IDEs will still put a line that looks like...
View Full Document

Page1 / 32

Lecture3 - CS213: C++ Programming Lecture #3: Library Types...

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online