C++ problem need your input
Page 1 of 4 123 ... LastLast
Results 1 to 10 of 32

Thread: C++ problem need your input

  1. #1

    C++ problem need your input

    Hi, I'm a total beginner in C++. I am using Bloodshed Dev C-++ 4.01 Compiler. Now Im trying to get Hello World program to run, it compiles successfully but it won't Run. The command prompt blinks for one second and it disappears. Basically, it wont execute. I've enlist the help of Mathgirl but shes not too familiar with the compiler Im using, I've looked through this thread
    I followed it but it wont work.


    It's from the book teach Yourself C++ in 24 hours, although It'll take more than that.

    This is the program I did:

    #include <iostream>

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


    It compiles successfully but like I said before it won't execute, I can't see the result Hello World. How do I get this simple program up and running? I appreciate any help.
    Light thinks it travels faster than anything but it is wrong. No matter how fast light travels it finds the darkness has always got there first, and is waiting for it.-Reaper Man

  2. #2
    () \/V |\| 3 |) |3\/ |\|3G47|\/3
    Join Date
    Sep 2002
    Posts
    744
    Vin, try this link, regarding system(“PAUSE”); .

    Go Finland!
    Deviant Gallery

  3. #3
    Senior Member
    Join Date
    Nov 2002
    Posts
    393
    add the following line to your code :
    add to the end, just before the return 0.

    getch();


    Another option is, first compile the code, run it, and press Alt+F5 to view the output.
    \"I have a 386 Pentium.\"

  4. #4
    () \/V |\| 3 |) |3\/ |\|3G47|\/3
    Join Date
    Sep 2002
    Posts
    744
    Invader, I use MS VisualC++6.0 and suggested in a PM that M/S Vin use getch();
    but it didn't work. I don't use Bloodshed but getch(); worked for me when I tried out his program.

    Go Finland!
    Deviant Gallery

  5. #5
    Senior Member
    Join Date
    Nov 2002
    Posts
    393
    Strange. even the Alt+F5 didnt work ?
    \"I have a 386 Pentium.\"

  6. #6
    Member
    Join Date
    Jan 2002
    Posts
    80
    1)I don't think there is an option to see the o/p using alt+F5 in Dev C++. the simplest thing is to include a getch() statement at the end of ur prog.

    2) Otherwise , u can run ur program thru the command prompt. just *cd* to the directory where ur prog is and then just enter the name of ur prog.

  7. #7
    er0k
    Guest
    #include <iostream>

    int main()
    {
    cout << "Hello, World!\n";
    cin.ignore();

    return 0;

    }

  8. #8
    Originally posted here by invader
    add the following line to your code :
    add to the end, just before the return 0.

    getch();


    Another option is, first compile the code, run it, and press Alt+F5 to view the output.
    When I click compile, it compiles successfully like I said before, right after; I click Run all I see is a blink with no output of the program.


    Originally posted here by shantz
    1)I don't think there is an option to see the o/p using alt+F5 in Dev C++. the simplest thing is to include a getch() statement at the end of ur prog.

    2) Otherwise , u can run ur program thru the command prompt. just *cd* to the directory where ur prog is and then just enter the name of ur prog.
    I've tried the getch(); command over and over but it really wont work.
    Here it is:

    #include <iostream>

    int main()
    {
    std::cout << "Hello World!\n";
    get ch();
    return 0;
    }


    Error Message is : Each undeclared identifier is reported only once for each function it appears in.
    Parse error before (
    Light thinks it travels faster than anything but it is wrong. No matter how fast light travels it finds the darkness has always got there first, and is waiting for it.-Reaper Man

  9. #9
    Member
    Join Date
    Jan 2002
    Posts
    80
    Hey Vin, U r using the getch() instruction wrongly. there is no space between get and ch as u wrote "get ch(); ". Try "getch();" (without the quotes obviously).
    Moreover, I don't quite remember clearly, but I think u need to include "conio.h" too.
    And yes, the second method I told must surely work.
    Hope that helps

  10. #10
    Originally posted here by er0k
    #include <iostream>

    int main()
    {
    cout << "Hello, World!\n";
    cin.ignore();

    return 0;

    }
    Erok, this one worked! Thanks! I appreciate it, and if anyone have some more to add please feel free to do so.
    Light thinks it travels faster than anything but it is wrong. No matter how fast light travels it finds the darkness has always got there first, and is waiting for it.-Reaper Man

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •