Back
Syntax
Study
Editor
Mode:
HTML
CSS
JavaScript
PHP
Reset
Run »
HTML / CSS / JS
// hello.cpp — classic first C++ program #include <iostream> // standard I/O declarations #include <string> // std::string // Declare a custom namespace to avoid collisions namespace myapp { std::string greet(const std::string& name) { return "Hello, " + name + "!"; } } // namespace myapp int main(int argc, char* argv[]) { // Fully-qualified standard library usage std::cout << myapp::greet("World") << std::endl; // argc holds the argument count; argv holds the values if (argc > 1) { std::cout << "First arg: " << argv[1] << " "; } // Demonstrate a local namespace alias namespace ma = myapp; std::cout << ma::greet("C++") << " "; return 0; // 0 == success } // Compile with: g++ -std=c++17 -Wall -Wextra -o hello hello.cpp // Run with: ./hello MyName
Result
Open