#include // THIS IS OPTIONAL // // You can ignore this example and still // earn 100% in ECE 150. // // This example is included for students // who are curious about what lies beneath // the friendlier C++ input/output facilities. // provides the C standard // input/output library in a form that can // be used from C++. // // One of its simplest output functions is // // std::putchar( ... ) // // which writes a single character to the // standard output stream, usually displayed // in your terminal or console. // // This is much more primitive than using // std::cout. For example, putchar cannot // directly print an integer such as 123. // To do that using only putchar, you would // first have to determine that the integer // consists of the characters // // '1', '2', '3' // // and then print those characters one at // a time. // // By contrast, the C++ iostream library // provides a much more convenient interface: // // std::cout << 123; // // The library performs the conversion from // the integer 123 to the characters "123" // for you. // Function declaration int main(); // Function definition int main() { // std::putchar(...) prints one character. // // A character literal is written using // single quotes, such as 'H'. std::putchar('H'); std::putchar('e'); std::putchar('l'); std::putchar('l'); std::putchar('o'); // The character '\n' is the newline // character. It tells the output stream // to begin a new line. // // The backslash introduces an escape // sequence: although '\n' is written // using two visible characters in the // source code, it represents one // character value. std::putchar('\n'); // Historically, different operating // systems used different sequences of // characters to represent the end of a // line in a text file: // // Unix and modern macOS: '\n' // Windows: "\r\n" // // '\r' is the carriage-return character. // // However, when a C or C++ program writes // '\n' to a text stream, the runtime // normally performs any operating-system- // specific translation that is required. // You therefore should not normally write // '\r' yourself just because the program // is running on Windows. // With C++ streams, we could instead write // // std::cout << '\n'; // // or // // std::cout << std::endl; // // These are not quite identical: // // '\n' // // inserts a newline, whereas // // std::endl // // inserts a newline and then flushes the // output stream, forcing buffered output // to be sent immediately. // // For ordinary output, '\n' is often the // better choice. We will discuss streams, // buffering, and flushing later. return 0; }