Patrick Dwyer

Echo :: C++

in News, Comparative Programming, C++ by patrick

This program is part of the Comparative Programming :: Echo set of examples.

The C++ example is nearly identical to the C example, with slight alterations for more common C++ libraries and idioms. The main method has the same signature, the for loop is the same, we even use the same technique of printing out each argument followed by a space. Instead of the printf method from C, we use IO Streams.

Just like our C program, the C++ example compiles to a native binary, sacrificing portability for speed and native architecture.

#include <iostream>

int main(int argc, char* argv[]) {

for (int i = 1; i < argc; i++) {
std::cout << argv[i] << " ";

std::cout << std::endl;


Program Source:

Compiling the example

From the command line:

g++ -o echo_cc

Running the example

From the command line:

./echo_cc Hello World