MSDN Documentation

Getting Started with C++

Welcome to the C++ documentation on MSDN! This guide will walk you through the essential steps to begin your C++ development journey, from setting up your environment to writing and running your first program.

Prerequisites: Basic understanding of programming concepts is helpful, but not strictly required.

1. Setting Up Your Development Environment

To write and compile C++ code, you'll need a C++ compiler and an Integrated Development Environment (IDE). Microsoft provides excellent tools for Windows development.

Recommended Tools:

2. Your First C++ Program: "Hello, World!"

Let's write a simple program that outputs "Hello, World!" to the console. This is a traditional first step for any new programming language.

Create a New Project (Visual Studio):

  1. Open Visual Studio.
  2. Select "Create a new project".
  3. Search for "Console App" and choose the C++ template.
  4. Name your project (e.g., "HelloWorldCpp") and choose a location.
  5. Click "Create".

Write the Code:

Your new project will likely have a default file (e.g., HelloWorldCpp.cpp) with the following code. If not, create a new C++ file and add this content:

#include <iostream>

int main() {
    std::cout << "Hello, World!" << std::endl;
    return 0;
}

Explanation of the Code:

3. Building and Running Your Program

Using Visual Studio:

  1. Press Ctrl + Shift + B or go to Build > Build Solution to compile your code.
  2. Press F5 or go to Debug > Start Debugging to run your program.

Using VS Code (with MSVC Build Tools or MinGW):

This process typically involves configuring tasks.json and launch.json to specify your compiler and build commands. Refer to the VS Code C++ configuration for detailed steps.

Once configured, you'll typically use commands like:

# Example compilation command (may vary)
g++ main.cpp -o hello
# Example run command
./hello

You should see the output:

Hello, World!

4. Next Steps

Congratulations! You've successfully set up your environment and run your first C++ program. Here are some resources to continue your learning:

Keep exploring, keep coding, and welcome to the powerful world of C++!