Lesson 1 of 19
Hello, C++!
Your First C++ Program
C++ is one of the most powerful and widely used programming languages ever created. Bjarne Stroustrup designed it at Bell Labs starting in 1979 as "C with Classes" — an extension of C that added object-oriented features. The name C++ came in 1983: applying the increment operator to C.
C++ vs C
C++ is a superset of C. Almost every valid C program is also valid C++. But C++ adds:
- Classes and objects — bundle data and behavior together
- Inheritance — share code between related classes
- Templates — write code that works for any type
- The Standard Library —
vector,string,map, algorithms, and more
Output with cout
In C, you use printf to print. C++ introduces a stream-based I/O system:
#include <iostream>
using namespace std;
int main() {
cout << "Hello, World!" << endl;
return 0;
}
#include <iostream>— includes the input/output stream libraryusing namespace std;— lets you writecoutinstead ofstd::coutcout— the standard output stream (likestdoutin C)<<— the insertion operator (feeds data into the stream)endl— inserts a newline and flushes the stream. You can also use"\n"for just a newline without flushing, which is faster in performance-sensitive code. For most learning exercises, either works fine
Chaining Output
You can chain multiple << operators:
cout << "Value: " << 42 << endl;
cout << "Pi is " << 3.14 << " approximately" << endl;
Your Task
Print Hello, C++! followed by a newline.
JSCPP loading...
Loading...
Click "Run" to execute your code.