Compiler Is Wierd

This is a discussion on Compiler Is Wierd within the C++ Programming forums, part of the General Programming Boards category; Hello...Let me tell you about my problem. I've been trying to figure this out for a pretty long time. Now, ...

  1. #1
    31173 h4x0r gnu-ehacks's Avatar
    Join Date
    Nov 2001
    Posts
    556

    Compiler Is Wierd

    Hello...Let me tell you about my problem.

    I've been trying to figure this out for a pretty long time. Now, whenever I try to compile a console program, it becomes wierd. When I cout before I call a function like "getch()", it carries out the function before the output. Here's an example:

    #include <iostream.h>
    #include <conio.h>

    int main()
    {
    cout << "Hello!\n";

    getch();

    return(0);
    }

    Now, this will usually ask for input before it outputs "Hello!".
    What will people say if they hear that I'm a Jesus freak?
    What will people do if they find that it's true?
    I don't really care if they label me a Jesus freak, there is no disguising the truth!

    Jesus Freak, D.C. Talk

    -gnu-ehacks

  2. #2
    Registered User
    Join Date
    Dec 2001
    Posts
    21
    m?
    thats weird. have u tried using
    #include <stdio.h>

    printf("Hello!\n");

  3. #3
    31173 h4x0r gnu-ehacks's Avatar
    Join Date
    Nov 2001
    Posts
    556
    Not yet, let me try now.
    What will people say if they hear that I'm a Jesus freak?
    What will people do if they find that it's true?
    I don't really care if they label me a Jesus freak, there is no disguising the truth!

    Jesus Freak, D.C. Talk

    -gnu-ehacks

  4. #4
    Registered User
    Join Date
    Aug 2001
    Posts
    101
    Flush cout before you call getch:
    Code:
    cout << "Hello\n" << flush;
    // or
    cout << "Hello" << endl;
    - lmov

  5. #5
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    Imov's solution will work, but in general, you should avoid mixing old style C I/O and C++ stream I/O as the buffering is different, (indeed absent in some cases).
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C Compiler and stuff
    By pal1ndr0me in forum C Programming
    Replies: 10
    Last Post: 07-21-2006, 12:07 PM
  2. I can't get this new compiler to work.
    By Loduwijk in forum C++ Programming
    Replies: 7
    Last Post: 03-29-2006, 06:42 AM
  3. how to call a compiler?
    By castlelight in forum C Programming
    Replies: 3
    Last Post: 11-22-2005, 11:28 AM
  4. Help With finding a compiler
    By macman in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 04-15-2005, 09:15 AM
  5. Wierd compiler error.
    By ninja in forum C++ Programming
    Replies: 7
    Last Post: 10-12-2002, 04:11 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21