![]() ![]() I will explain their meaning later.ĭefines the so-called main() function. ![]() These two lines shall be present in all our programs. The names cout and endl, which is used in this program, belong to the std namespace. The " using namespace std " statement declares std as the default namespace used in this program. The directive " #include " tells the preprocessor to include the " iostream" header file to support input/output operations. ![]() Preprocessor directives begin with a # sign. The " #include" is called a preprocessor directive. End-of-line Comment: begins with // and lasts until the end of the current line (as in Lines 4, 7, 8, 9 and 10).It may span more than one lines (as in Lines 1-3). Multi-line Comment: begins with /* and ends with */.Comments are NOT executable and are ignored by the compiler but they provide useful explanation and documentation to your readers (and to yourself three days later). UNIX/Linux/Mac (Bash shell) - Run "hello" (./ denotes the current directory) Windows (CMD shell) - Run "hello.exe" (.exe is optional) On Text Editor with GNU GCC compiler, issue these command from CMD Shell (Windows) or Terminal (UNIX/Linux/Mac):.On IDE (such as CodeBlocks), push the "Run" button.Step 3: Run the Executable Code: Execute (Run) the program. Where g++ is the name of GCC C++ compiler -o option specifies the output filename (" hello.exe" for Windows or " hello" for UNIX/Linux/Mac) " hello.cpp" is the input source file. UNIX/Linux/Mac (Bash shell) - Build "hello.cpp" into "hello" #include // Needed to perform IO operations * First C++ program that says hello (hello.cpp) You should choose a filename which reflects the purpose of the program. ![]() A C++ source file should be saved with a file extension of ". Step 1: Write the Source Code: Enter the following source codes using a programming text editor (such as NotePad++ for Windows or gedit for UNIX/Linux/Mac) or an Interactive Development Environment (IDE) (such as CodeBlocks, Eclipse, NetBeans or Visual Studio - Read the respective "How-To" article on how to install and get started with these IDEs).ĭo not enter the line numbers (on the left panel), which were added to help in the explanation. Let us begin by writing our first C++ program that prints the message "hello, world" on the display console. Getting Started - Write our First Hello-world C++ Program ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |