next up previous contents index
Next: The LEDA Manual Page Up: Basics Previous: Basics   Contents   Index

Getting Started

Please use your favourite text editor to create a file prog.c with the following program:

#include <LEDA/core/d_array.h>
#include <LEDA/core/string.h>
#include <iostream>

using std::cin;
using std::cout;
using std::endl;
using leda::string;
using leda::d_array;

int main()
  d_array<string,int> N(0);
  string s;
  while (cin >> s) N[s]++;
  forall_defined (s,N) 
    cout << s << " " << N[s] << endl;

  return 0;

If you followed the installation guidelines (see Chapter TechnicalInformation ff.), you can compile and link it with LEDA's library libleda (cf. Section Libraries). For example, on a Unix machine where g++ is installed you can type

g++ -o prog prog.c -lleda -lX11 -lm

When executed it reads a sequence of strings from the standard input and then prints the number of occurrences of each string on the standard output. More examples of LEDA programs can be found throughout this manual.

The program above uses the parameterized data type dictionary array (d_array<I,E>) from the library. This is expressed by the include statement (cf. Section Header Files for more details). The specification of the data type d_array can be found in Section Dictionary Arrays. We use it also as a running example to discuss the principles underlying LEDA in the following sections.