Hello World
This tutorial dives into the essentials of C++ programming starting with the classic "Hello World!" example. It covers the basic syntax, the role of the `iostream` library for input-output operations, and explains the `main` function necessary for all C++ programs. You will also learn how to manipulate strings and perform basic operations, such as printing and modifying string content. This guide is perfect for beginners looking to understand the fundamentals of C++ coding.
Hello World
E N D
Presentation Transcript
Hello World #include <iostream> using namespace std; int main () { cout << "Hello World!"; return 0; }
#include <iostream> • This specific file (iostream) includes the declarations of the basic standard input-output library in C++. • using namespace std; • All the elements of the standard C++ library are declared within what is called a namespace. • int main () • it is essential that all C++ programs have a main function • { • cout << "Hello World!"; • cout (and cin) represents the standard output stream in C++, • return 0; • }
// my second program in C++ #include <iostream> using namespace std; int main () { cout << "Hello World! "; cout << "I'm a C++ program"; return 0; }
// my first string #include <iostream> #include <string> using namespace std; int main () { string mystring; mystring = "This is the initial string content"; cout << mystring << endl; mystring = "This is a different string content"; cout << mystring << endl; return 0; }
endl // endl #include <iostream> usingnamespace std; int main () { int a=100; double b=3.14; cout << a; cout << endl; // manipulator inserted alone (adds newline) cout << b << endl << a*b; // manipulator in concatenated insertion return 0; }