![]() ![]() Both name the same object: the first one uses its unqualified name ( cout), while the second qualifies it directly within the namespace std (as std::cout).Ĭout is part of the standard library, and all the elements in the standard C++ library are declared within what is called a namespace: the namespace std. If you have seen C++ code before, you may have seen cout being used instead of std::cout. If comments are included within the source code of a program without using the comment characters combinations //, /* or */, the compiler takes them as if they were C++ expressions, most likely causing the compilation to fail with one, or several, error messages. Std::cout << "I'm a C++ program" // prints I'm a C++ program Std::cout << "Hello World! " // prints Hello World! With more comments */ #include int main () But C++ does not have strict rules on indentation or on how to split instructions in different lines. The program has been structured in different lines and properly indented, in order to make it easier to understand for the humans reading it. ![]() The execution of all C++ programs begins with the main function, regardless of where the function is actually located within the code. The function named main is a special function in all C++ programs it is the function called when the program is run. Functions will be discussed in detail in a later chapter, but essentially, their definition is introduced with a succession of a type ( int), a name ( main) and a pair of parentheses ( ()), optionally including parameters. ![]() Essentially, a function is a group of code statements which are given a name: in this case, this gives the name "main" to the group of code statements that follow. Line 4: int main () This line initiates the declaration of a function. They simply improve readability of the code. In this case, the directive #include, instructs the preprocessor to include a section of standard C++ code, known as header iostream, that allows to perform standard input and output operations, such as writing the output of this program ( Hello World) to the screen. They are special lines interpreted before the compilation of the program itself begins. Std::cout Lines beginning with a hash sign ( #) are directives read and interpreted by what is known as the preprocessor. my first program in C++ #include int main() ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |