Unformatted text preview: th: for basic math functions (e.g., sqrt)
5 What happens if an include is missing?
x Let’s try!
x In general, the compiler doesn’t know which file declares
In the class you want
x Use Google/documentation to know the file to include 6 Common pitfalls with includes
x Forgetting to include a header file
x Including files in the wrong order, for dependent headers Note: if it is well programmed, this problem should never arise
x Including a header that includes itself, without protection example: #include “foo.hpp” from “bar.hpp”, which itself starts by
including “bar.hpp” 7 Some syntax example
x Include a system-provided header, called iostream: #include <iostream>
x Include your own header file (extension: .h, .hpp, .hh) #include “myfile.hpp”
x Be careful about where the file is located: the compiler
Be must know where to find the header
must The compiler knows the system include directories, but not your
development 8 Console output
std::cout << “Hello World!” << std::endl;
xThis is read “push to cout the string Hello World, and then
This push a newline”
xSyntax std::cout is used to refer to the default console output “foo bar” is a (constant) string << is a binary operator, roughly meaning “push <rhs> in <lhs>” std::endl is used to refer to a newline symbol (\n) 9 A few examples
std::cout << “foo”;
std::cout << std::endl;
// equivalent to std::cout << “foo” << std::endl;
std::cout << “Hello” << “ “ << “World” << std::endl;
// equivalent to std::cout << “Hello World” << std::endl; 10 Printing out variables
x << can sup...
View Full Document
This note was uploaded on 04/03/2014 for the course CS 31 taught by Professor Melkanoff during the Fall '00 term at UCLA.
- Fall '00