Thread: Problem with std::cin

  1. #16
    Registered User Kybo_Ren's Avatar
    Join Date
    Sep 2004
    Posts
    136
    Why not just separate these tasks into separate functions?

  2. #17
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    no you don't... you can do that from deep within main or from right in main if you really think about it... but starting from main again is NOT the way to do it...

    for example:

    Code:
    int main()
    {
        char*classname=new char[120];
        int classnum;
    
        for(;;)
        {
            cout<<"Enter the class name: ";
            cin.getline(classname,120,'\n');
            cout<<"Enter the class number: ";
            cin>>classnum;
    
            //don't forget some way to exit the program eventually...
    
            createclass(classname,classnum);
            checkclasses();
        }
    
        delete&#091;&#093;classname;
        return 0;
    }
    Last edited by major_small; 10-23-2004 at 06:55 PM.
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  3. #18
    C(++)(#)
    Join Date
    Jul 2004
    Posts
    309
    Quote Originally Posted by Kybo_Ren
    Why not just separate these tasks into separate functions?
    I did.

    no you don't... you can do that from deep within main or from right in main if you really think about it... but starting from main again is NOT the way to do it...
    I figured there was an easier way to do it. I'll go do some reasearch and look into that, thanks *adds rep*
    To code is divine

  4. #19
    Registered User Kybo_Ren's Avatar
    Join Date
    Sep 2004
    Posts
    136
    What I meant was why not just put what you're doing in main in a different function, then in main() call that function. That way you can call it however many times you want.

  5. #20
    C(++)(#)
    Join Date
    Jul 2004
    Posts
    309
    Thanks major_small, that will help me ALOT.
    To code is divine

  6. #21
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >but I'm wondering if there's actually a clause in the standard that says that you can't do that...
    "The function main shall not be used within a program." from section 3.6.1 seems to cover it pretty well.
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  2. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  3. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  4. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM
  5. cin problem
    By mikahell in forum C++ Programming
    Replies: 12
    Last Post: 08-22-2006, 11:14 AM