next up previous contents
Next: Stack-based allocation Up: A Quick Introduction Previous: A Quick Introduction   Contents

Standard 'Hello World' Program

Presented below is a simple version of 'Hello World' that uses the Str class. Although not impressive, it is a good first step in getting comfortable with Str. Here is the C-style I/O version:

#include "Str.hpp"
#include <stdio.h>

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

    // Create a string on the Heap and print it

    Str s = "Hello World!";
    printf("s = %s\n", (const char*)s);
        
    // Set it equal to something and print it again

    s = "Goodbye!";
    printf("now s = %s\n", (const char*)s);

    return 0;
    
}

And here is the same version that uses C++-style I/O:

#include "Str.hpp"
#include <iostream>
using namespace std;

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

    // Create a string on the Heap and print it

    Str s = "Hello World!";
    cout << "s = " << s << endl;
        
    // Set it equal to something and print it again

    s = "Goodbye!";
    cout << "now s = " << s << endl;

    return 0;
    
}

Look at your favorite version and we'll review some concepts:


next up previous contents
Next: Stack-based allocation Up: A Quick Introduction Previous: A Quick Introduction   Contents
2007-05-05