Quiz Entry - updated: 2026.06.23
How do you write "Hello, world!" in C++?
Include <iostream>, then write cout << "Hello, world!" << endl; inside main().
#include <iostream>
using namespace std;
int main(void) {
cout << "Hello, world!" << endl;
return 0;
}
Key C++ elements:
#include <iostream>— C++ stream I/O library (not C'sstdio.h)using namespace std;— lets you writecoutinstead ofstd::coutcout <<— sends text to the output stream (the C++ replacement forprintf)endl— writes a newline and flushes the buffer (or use"\n"for just the newline)
Compile and run:
$ g++ -o hello hello.cpp
$ ./hello
Hello, world!