The original content has been adapted for article format. Code has been migrated to Visual Studio 2017 and will take advantage of the good stuff for C++ developers in Visual Studio 2017. Screenshots and other behaviors will be from Visual Studio 2017. Code has been changed to reflect modern views on correctness, style, or usage where appropriate.
There are plenty of resources for new and experienced C++ developers. We recommend the C++ Primer, 5th Edition by Lippman, Lajoie, and Moo. It uses modern constructs without revisiting older techniques that are better left in the past. Visit isocpp.org for a list of helpful resources, the latest C++ news, and pointers to interesting content across the internet.
This tutorial will be hands-on and coding oriented, so follow along! You can use Visual Studio Community, a fully-featured, extensible, free IDE for creating modern applications in C++ for Windows, Linux, and other platforms. You can also use use different compilers like GCC and Clang in Visual Studio.
Designed by Bjarne Stroustrup, C++ has been around for more than three decades. Born in 1979 as C with Classes, it retains backward compatibility with C with improvements in data abstraction and support for object oriented programming and generic programming.
C and C++ are popular because they are portable and can be compiled, without major changes, across different compilers or different computer hardware, operating systems, CPU architectures, or device form factors. Each platform or operating system may have different compilers available from different providers such as Microsoft, Intel, or the open source community.
Most of the code you encounter while learning C++ can be run using simple text input with text output directly to a console window. These tutorials will use an empty project configured as a console application. You can add new source files and code and see the results on the command line.
Line 3: Every C++ program must have a function known as main(). It is referred to as the entry point for the application when you start execution of the program on your computer. The int portion is the return type of the method. The empty parentheses () after the name indicate that this a function and that it takes no arguments, in other words, there are no parameters for passing in values. You will learn more about variable types, return value and arguments in the future.
Line 6: The return statement is used to end a function when a value is expected to be sent back to a caller. In this case, the caller is the operating system and the value returned is an integer value of 0. If the program reaches this statement, returning a value of 0 is an indication to the operating system that the code executed successfully. Programmers return 0 to indicate successful execution and non-zero values to indicate that an error had occurred in the program somewhere.
Line 7: This line closes out the body of the function main() and is necessary so the compiler knows where the function or method ends, but is also used for other purposes that will be covered later in the course on variable scope and visibility.
There are more complicated applications, but the cool thing about C++ is that every scrap of syntax and library you learn to write a console application you can use to write any other kind of application at all.
After every source file has been compiled, the linker links object files together into the application that is executed by the computer processor. The linker makes sure any promises you made in code are being kept. For example, in Hello, World, std::cout is defined elsewhere. The linker must resolve the call when it pulls in the iostream library.
If you have any feedback or suggestions for us, please reach out. We can be reached via the comments below, via email (ebat...@microsoft.com or visu...@microsoft.com) and you can provide feedback via Help > Report A Problem in the product, or via Developer Community. You can also find us on Twitter (@VisualC) and Facebook (msftvisualcpp).
A visual studio code is a lightweight software application with a powerful source code editor that runs on the desktop. It is a free source code editor developed by Microsoft for Windows, Mac OS and Linux. It is a software editor that has a rich extension of various languages like C++, C+, C, Java, Python, PHP, Go, etc. and runtime language extensions such as .NET and Unity. It is easy to edit, build, syntax highlighting, snippets, code refactoring and debugging. In visual studio code, we can change the application's background theme, keyboard shortcuts set on our preferences, install an extension and add additional functionality.
d3342ee215