Thread: I don't think this is supposed to happen.

  1. #1
    Mako Eyes
    Guest

    I don't think this is supposed to happen.

    When I use an INT program, something goes wrong.

    Here's a little example:

    int main()
    {
    cout<<"Stupid int main thingy!! I'm sick of it!!";
    system("PAUSE");
    return 0;
    }

    It runs fine the first time, but when I try again it says "implicit declaration of function `int system(...)'"

    In order to get it going again, I have to start a new project.

    Anybody know what's going on and how to fix it?

    Thanks.

  2. #2
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    Include some headers.
    Also, consider using namspace std.
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  3. #3
    Bios Raider biosninja's Avatar
    Join Date
    Jul 2002
    Location
    South Africa
    Posts
    765
    Well, this works for me :

    Code:
    #include <stdlib.h>
    #include <iostream.h>
    
    int main()
    {
        cout<<"Stupid int main thingy!! I'm sick of it!!";
        system("PAUSE");
        return 0;
    }
    *Borland C++ 5.02*

  4. #4
    I lurk
    Join Date
    Aug 2002
    Posts
    1,361
    What compiler are you using?

  5. #5
    Registered User
    Join Date
    Jun 2002
    Posts
    230
    Well like they said it all depends what compiler your using. Also with system("Pause") You have to use the <stdlib.h> header file. Some compilers need .h others dont. Some dont pick up std::. Tell us what compiler and we can help

  6. #6
    Mako Eyes
    Guest
    My compiler. . .

    Bloodshed Dev-C++
    version4

  7. #7
    mako Eyes
    Guest
    I had thos things included, i just didn't show them when I posted.

  8. #8
    Registered User
    Join Date
    Jun 2002
    Posts
    230
    Im using Dev c++ and dont have that problem. Works fine with me. are you still having problems?
    C++ Rules!!!!
    ------------
    Microsoft Visual Studio .NET Enterprise

  9. #9
    Just a Member ammar's Avatar
    Join Date
    Jun 2002
    Posts
    953
    When you wrote int main() did you write INT main() by mistake?
    Because they are different.

  10. #10
    Registered User
    Join Date
    Aug 2001
    Posts
    101
    Code:
    #include <cstdlib>
    #include <iostream>
    
    int main()
    {
        std::cout << "Stupid int main thingy!! I'm sick of it!!";
        std::system("pause");
    }
    C++ puts everything in namespace std (except macros of course).
    - lmov

  11. #11
    Mako Eyes
    Guest
    Okay, I got it now. . . I had to include 'cstdlib'.

    Thanks for the advice.

  12. #12
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    Code:
    #include <cstdlib>
    #include <iostream>
    
    int main()
    {
        std::cout << "Stupid int main thingy!! I'm sick of it!!";
        std::system("pause");
    }
    Where's the return value? Great thinking imov!
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  13. #13
    ˇAmo fútbol!
    Join Date
    Dec 2001
    Posts
    2,138
    Hunter, you are about to be crapped on. (JK)

    In C++, when you declare main to return int, the default return value is 0. Hence, by standard C++'s definition, return 0 isn't needed. But, some compilers might choke if you don't include it b/c not all compilers are completely standard.

  14. #14
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    Eww, where'd all this brown stinky stuff come from?

    I think I better delete my post lol oh wait, what about those people whose compilers would choke? NO, I'd better leave it!
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. magic could happen on recvfrom
    By -EquinoX- in forum C Programming
    Replies: 22
    Last Post: 03-27-2009, 06:06 PM
  2. Is This Supposed To Happen? [Dynamic Memory]
    By Dark Dude in forum C Programming
    Replies: 3
    Last Post: 03-21-2009, 05:41 PM
  3. Hey, what would happen if...
    By Imperito in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 04-05-2002, 08:54 AM
  4. What would happen?
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 04-04-2002, 10:54 AM
  5. Replies: 4
    Last Post: 03-04-2002, 03:37 PM