Setting up a C++ Development Environment

C++ File Extensions

What's the difference between 'main.cpp' and other file extensions like '.txt'?

3D art showing a blacksmith character

File extensions tell both the computer and the programmer what kind of file we're working with. For C++ programs, we typically use .cpp, but there are several related extensions you might encounter:

Common C++ Extensions

  • .cpp - Main C++ source files (most common)
  • .cc - Alternative C++ source extension (common in Linux)
  • .h or .hpp - Header files (we'll learn about these later)
  • .c - C language source files (C++ is based on C)

The main difference is how your computer and IDE treat these files:

// main.cpp - will be compiled as C++
#include <iostream>
using namespace std;

int main() {
  cout << "This is a C++ program!";
}

If we saved the exact same code as main.txt:

  • The IDE won't syntax highlight it properly
  • The compiler won't recognize it as code
  • We can't build and run it directly

Why Extensions Matter

The extension tells your development tools:

  • Which syntax highlighting to use
  • Whether the file should be compiled
  • Which compiler settings to use
  • Which language rules to enforce

For example, saving a C++ file as .c might cause issues:

// main.c - compiler will treat this as C code

// C doesn't have iostream!
#include <iostream>  

int main() {
  // cout doesn't exist in C
  std::cout << "This won't compile as C!";  
}

Different Extensions for Different Tools

Some IDEs create additional files with their own extensions:

  • .sln - Visual Studio solution files
  • .vcxproj - Visual Studio project files
  • .o or .obj - Compiled object files
  • .exe - Windows executable (the final program)

For now, just remember to save your C++ code files with the .cpp extension - this ensures your development environment will treat them properly as C++ source code.

Answers to questions are automatically generated and may not have been reviewed.

3D art showing a progammer setting up a development environment
Part of the course:

Intro to C++ Programming

Become a software engineer with C++. Starting from the basics, we guide you step by step along the way

Free, unlimited access

This course includes:

  • 60 Lessons
  • Over 200 Quiz Questions
  • 95% Positive Reviews
  • Regularly Updated
  • Help and FAQ
Free, Unlimited Access

Professional C++

Comprehensive course covering advanced concepts, and how to use them on large-scale projects.

Screenshot from Warhammer: Total War
Screenshot from Tomb Raider
Screenshot from Jedi: Fallen Order
Contact|Privacy Policy|Terms of Use
Copyright © 2024 - All Rights Reserved