cs31 lecture 4

G sqrt 5 what happens if an include is missing x lets

Info iconThis preview shows page 1. Sign up to view the full content.

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

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 the 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 which 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 The development directory! development 8 Console output std::cout << “Hello World!” << std::endl; std::cout xThis is read “push to cout the string Hello World, and then This push a newline” push 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.

Ask a homework question - tutors are online