Learn how to set up your C++ development environment, write your first program, compile and run it, and troubleshoot common errors.
#include <iostream>
– Includes the iostream library, which provides input and output functionality.int main()
– The main function is the starting point of every C++ program.std::cout << "Hello, World!" << std::endl;
– Uses cout (character output) from the std (standard) namespace to print text to the console.return 0;
– Indicates that the program has executed successfully.std::cout
is like speaking into that megaphone, and std::endl
is equivalent to taking a breath before speaking again.
cd path/to/file
).Ctrl + Shift + B
to compile and run the program.Error | Cause | Solution |
---|---|---|
cout was not declared | Missing std::cout or using namespace std; | Use std::cout or add using namespace std; |
int main should return int | main() function must return an integer | Ensure return 0; is present |
undefined reference to main | Compiler can’t find main() | Check function signature: int main() |