Thread: Too fast to test!

  1. #1
    The Defective GRAPE Lurker's Avatar
    Join Date
    Feb 2003
    Posts
    949

    Exclamation Too fast to test!

    I compiled this with the Digital Mars compiler:
    Code:
    #include <iostream.h>
    
    int main()
    
    {
    
      cout<<"HEY, you, I'm alive!  Oh, and Hello World!";
    
      return 0;    
    
    }
    And it compiles perfectly, however, when I run the test.exe program, it opens command prompt and closes it before I can see the results! Also, what are the .map and .obj files it creates? Can I delete those without error? Any help appreciated, thanks!

  2. #2
    Registered User abrege's Avatar
    Join Date
    Nov 2002
    Posts
    369
    Theres nothing that keeps it open. Try this..
    Code:
    #include <iostream>
    #include <conio.h>
    using namespace std;
    
    int main()
    {
         cout << "Hello world yadda yadda yadda";
         getch();
    
         return 0;
    }
    I am against the teaching of evolution in schools. I am also against widespread
    literacy and the refrigeration of food.

  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >getch();
    Why does everyone insist on using a nonportable construct for something so simple?
    Code:
    #include <iostream>
    
    int main()
    {
      std::cout<<"Hello, world!"<<std::endl;
    
      std::cout<<"Press return to continue"<<std::flush;
      std::cin.get();
    }
    You do realize that when the computer asks for any key to be pressed, the most common action is to hit return? In that case the effect of getch taking anything is wasted, so it would be better to lose a little flexibility that isn't often used and improve portability.

    -Prelude
    Last edited by Prelude; 03-05-2003 at 09:03 AM.
    My best code is written with the delete key.

  4. #4
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    For future reference, check this for answers to common questions.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  5. #5
    Registered User
    Join Date
    Jan 2003
    Posts
    56
    i use dev-c++

    i don't know if it works with other compilers
    so heres the code

    PHP Code:
    system ("pause"); 
    if x == y , y == x

  6. #6
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >i don't know if it works with other compilers
    It depends on whether or not "pause" is a system command for that machine.

    -Prelude
    My best code is written with the delete key.

  7. #7
    ! |-| /-\ +3 1337 Yawgmoth's Avatar
    Join Date
    Dec 2002
    Posts
    187
    Originally posted by gamer
    i use dev-c++

    i don't know if it works with other compilers
    so heres the code

    PHP Code:
    system ("pause"); 
    You have to #include <stdlib.h> too.
    L33t sp3@k sux0rz (uZ it t@k3s 10 m1|\|ut3s 2 tr@nzl@te 1 \/\/0rd & th3n j00 h@\/3 2 g3t p@$t d@ m1zpelli|\|gz, @tr0(i0u$ gr@mm@r @|\|d 1n(0/\/\pr3#3|\|$1bl3 $l@|\|g. 1t p\/\/33nz j00!!

    Speling is my faverit sujekt

    I am a signature virus. Add me to your signature so that I may multiply.

  8. #8
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >You have to #include <stdlib.h> too.
    You mean <cstdlib>, <stdlib.h> isn't a C++ header.

    -Prelude
    My best code is written with the delete key.

  9. #9
    ! |-| /-\ +3 1337 Yawgmoth's Avatar
    Join Date
    Dec 2002
    Posts
    187
    I'm pretty sure it's <stdlib.h>. Unless I've been using a non C++ header in all my C++ programs.
    L33t sp3@k sux0rz (uZ it t@k3s 10 m1|\|ut3s 2 tr@nzl@te 1 \/\/0rd & th3n j00 h@\/3 2 g3t p@$t d@ m1zpelli|\|gz, @tr0(i0u$ gr@mm@r @|\|d 1n(0/\/\pr3#3|\|$1bl3 $l@|\|g. 1t p\/\/33nz j00!!

    Speling is my faverit sujekt

    I am a signature virus. Add me to your signature so that I may multiply.

  10. #10
    Registered User
    Join Date
    Sep 2002
    Posts
    54
    This is easy.
    Code:
    #include <iostream.h>
    
    int main()
    
    {
    
      cout<<"HEY, you, I'm alive!  Oh, and Hello World!";
    // i added line below
    cin >> hold;
      return 0;    
    
    }
    Add a cin>>hold; above return 0; and that should do it.

  11. #11
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >Unless I've been using a non C++ header in all my C++ programs.
    You have. Many implementations support the C headers since that is what C++ used to use. However, those headers are now no longer part of the language proper.

    >Add a cin>>hold; above return 0; and that should do it.
    Where do you define hold, and why do you even need a variable? See my first post on this thread.

    -Prelude
    My best code is written with the delete key.

  12. #12
    ! |-| /-\ +3 1337 Yawgmoth's Avatar
    Join Date
    Dec 2002
    Posts
    187
    No longer part of the language proper? Does that mean they're like void main()?
    L33t sp3@k sux0rz (uZ it t@k3s 10 m1|\|ut3s 2 tr@nzl@te 1 \/\/0rd & th3n j00 h@\/3 2 g3t p@$t d@ m1zpelli|\|gz, @tr0(i0u$ gr@mm@r @|\|d 1n(0/\/\pr3#3|\|$1bl3 $l@|\|g. 1t p\/\/33nz j00!!

    Speling is my faverit sujekt

    I am a signature virus. Add me to your signature so that I may multiply.

  13. #13
    Geek. Cobras2's Avatar
    Join Date
    Mar 2002
    Location
    near Westlock, and hour north of Edmonton, Alberta, Canada
    Posts
    113
    void main() never was part of the language afaik, nor was it part of C;
    with regards to <stdlib.h> that was C, but it is only included in C++ for backwards-compatibility. (I believe?)
    James G. Flewelling
    Rgistered Linux User #327359
    Athabasca University Student (BSc. CIS)

    http://catb.org/~esr/faqs/smart-questions.html
    http://catb.org/jargon/

    http://www.ebb.org/ungeek
    ---GEEK CODE---
    Version: 3.12
    GCS/IT/M d- s+:++ a-->->>+>++>+++>? C++++>$ UL++>++++$ P++>++++ L++>++++$
    E W++ N o? K? w++(--)>--- O? M? V? PS--(---) PE Y+ PGP? t 5? !X R(*)>++
    tv-->! b++(+++)>++++ DI? D+++(---)>++++$ G e*>++$ h++>*$ r!>+++ y?
    ----/GEEK CODE----
    upd: 2005-02-11

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sustring test puzzle
    By WDT in forum C# Programming
    Replies: 3
    Last Post: 06-29-2009, 07:19 AM
  2. Help needed to verify a new on-line C test
    By JanHruska in forum Projects and Job Recruitment
    Replies: 15
    Last Post: 06-20-2009, 06:48 AM
  3. Creating C/C++ Unit Test Cases
    By chiefmonkey in forum C++ Programming
    Replies: 1
    Last Post: 04-28-2009, 08:29 PM
  4. malloc () test
    By Unregistered in forum C Programming
    Replies: 5
    Last Post: 07-08-2002, 05:20 PM