Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

C++ Console app, Hello World! Problem

Name: Anonymous 2006-07-05 19:44

Im just starting C++ but i have got stuck straight away!

I have:

#include <iostream>
using namespace std;

int main()
{
    cout << "Hello World!\n" << endl;
    return 0;
}


It works fine, but just as it appears, it closes..and in the tutorial it shows the console with: 'press any key to continue...' under 'Hello World!'. Please Help!

Name: Anonymous 2006-07-08 0:37

Dear prog,
Related to this, I just figured out something weird.
#include <stdlib.h>
#include <stdio.h>

int main(void) {
    char text[BUFSIZ];
    int i;

    puts("enter a number");
    if (fgets(text, sizeof(text), stdin) != NULL) {
       i = atoi(text);
       printf("you entered %d\n", i);
    }
    return 0;
}
When I compile that with MingW, it skips the puts call entirely. I mean I could be doing anything but this happens all the time. Any idea? My code does work. It just comes out like:

$ ./junk
42
enter a number
you entered 42

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List