Zamples, Inc. logo
 Home   Search   Solutions   My Zamples   FAQ   News   Contact 
Zamples ID:
Password:
   
0 anonymous users;
48 users logged in.

Live Samples
Live APIs

HTML or JSP Frag
Java Servlet Frag
HTML & Applet
Bash
C# (Mono)
C++ (gcc)
Groovy
Haskell (Hugs98)
J2SE 1.4 Class
J2SE 1.4 Fragment
J2SE 5.0 Class
J2SE 5.0 Fragment
J2SE 6.0 Class
J2SE 6.0 Fragment
Perl
Python
Ruby
 

GCC Sample Code

Zamples is proud to announce support for C, C++, Objective C and Fortran code examples, powered by GCC.

We show each example twice on this page.  The first version of the example is shown in its entirety, next to a "Try It!" button - we call this the 'read-only' code example, because it doesn't come from a database, and any changes you make can't be posted back to the community. Feel free to copy the example code and paste it into your own programs. The community postings follow, with "New" and "Reply" buttons added.  As with the read-only code example, you can run the code example, modify it and rerun it.

Unlike the read-only code examples, community postings allow you to create new discussion threads, or reply to an existing posting.  After you click on a 'Try It!' button in a community posting, or after you press a 'New' button to start a new discussion thread, edit your code, select the type of program (C#), and then 'Run It!' until it works.  When you click on the 'Save' button, the New Posting Wizard will appear.  The wizard will prompt you for information about your code example, and then save it to the database.  Each posting contains a code example, plus comments about the code.  Next time you refresh this page your new posting will appear.

Learn more about Zamples and play with samples for other APIs.

We would love to hear your feedback.

Zamples presets the GCC v3.4.3 options to -Wall -Wno-deprecated -lstdc++.  You can add to them.  You can control the dialect of C, C++ or Objective-C with the appropriate options.  Zamples saves the program that your run in a file with a .cpp filetype.

Separate the options and the arguments with --.

The -x option allows you to specify explicitly the language for the following input files. This option applies to all following input files until the next -x option. Possible values for language are: c, c-header, cpp-output, c++, c++-header, c++-cpp-output objective-c, objective-c-header, objc-cpp-output, assembler, assembler-with-cpp, ada, f77, f77-cpp-input, ratfor, java, treelang.

Hello Zamples

The famous "Hello, world" C program has changed over the years.  Here is how it looks, written in modern C++.

#include <iostream>
using namespace std;
int main() {
   cout << "Hello, Zamples!";
}

Sample output:

Hello, Zamples!
to add a new posting or reply to an existing posting.

Print Command Line Arguments

#include <iostream>
using namespace std;
int main(int argc, char* args[]) {
   cout << "Number of command line parameters = " << argc-1 << endl;
   for (int i=1; i<argc; i++) 
      cout << "arg[" << i-1 << "] = " << args[i] << endl;
}

Sample output:

Number of command line parameters = 3
arg[0] = one
arg[1] = two
arg[2] = three
to add a new posting or reply to an existing posting.