My first program....

Discussion in 'Programming General' started by evil-oreo, May 12, 2008.

My first program....
  1. Unread #1 - May 12, 2008 at 4:48 AM
  2. evil-oreo
    Joined:
    Dec 3, 2005
    Posts:
    40
    Referrals:
    0
    Sythe Gold:
    0

    evil-oreo Member

    My first program....

    //Hello Sythe.org
    //My first C++ program

    #include <iostream>

    using namespace std;

    int main ()
    {

    cout << "Hello Sythe.org!" << endl;
    return 0; /* I dont know how to make the window stay open though.
    Also, this is all from memory. I think I posted a couple programs before, but copyed someone else.*/

    }
     
  3. Unread #2 - May 12, 2008 at 1:44 PM
  4. Nullware
    Joined:
    Jan 30, 2007
    Posts:
    1,761
    Referrals:
    4
    Sythe Gold:
    0

    Nullware Guru

    My first program....

    This shows you how to keep it open by waiting for user input.

    Code:
    //Hello Sythe.org
    //My first C++ program
    
    #include <iostream>
    
    using namespace std;
    
    int main ()
    {
    cout << "Hello Sythe.org!" << endl;
    cout << "Press any key to exit...";
    getchar();
    return 0; 
    /* I dont know how to make the window stay open though.
    Also, this is all from memory. I think I posted a couple programs before, but copyed someone else.*/
    }
     
  5. Unread #3 - May 21, 2008 at 8:38 AM
  6. fareed
    Joined:
    Jul 2, 2005
    Posts:
    2
    Referrals:
    0
    Sythe Gold:
    0

    fareed Newcomer

    My first program....

    hi evil-oreo,

    If you used dev c++ compiler, add

    system("pause");

    example:


    #include <iostream.h>

    using namespace std;

    int main ()
    {

    cout << "Hello Sythe.org!" << endl;

    system("PAUSE");

    return 0;

    }

    you can also clear the screen by adding:

    system("cls");

    example:

    #include <iostream.h>

    using namespace std;

    int main ()
    {

    cout << "Hello Sythe.org!" << endl;

    system("cls");

    cout << "Hello world!" << endl;

    system("PAUSE");

    return 0;

    }
     
  7. Unread #4 - May 21, 2008 at 5:30 PM
  8. Swan
    Joined:
    Jan 23, 2007
    Posts:
    4,957
    Referrals:
    0
    Sythe Gold:
    0
    Sythe's 10th Anniversary Member of the Month Winner

    Swan When They Cry...
    Retired Global Moderator

    My first program....

    That's terrible, terrible code. What if I use a UNIX or *NIX environment? DOS commands are worthless there.

    Use cross-platform libraries, if you are to use any at all. It'll save you a lot of trouble.

    Edit: In response to the first post, to keep the window open, use the following:

    Add the following header:
    Code:
    #include <conio.h>
    Then before you return 0 from your main method, add this:
    Code:
    getchar();
    simple, cross-platform (I think =/) and works generally effectively.
     
  9. Unread #5 - May 21, 2008 at 7:13 PM
  10. Nullware
    Joined:
    Jan 30, 2007
    Posts:
    1,761
    Referrals:
    4
    Sythe Gold:
    0

    Nullware Guru

    My first program....

    1. The getchar() function is defined in the <iostream> include and is therefore cross-platform.

    2. The conio.h header which does not include getchar() is not cross-platform. It does however include the similar getch() function which you might have been thinking of.;)
     
  11. Unread #6 - May 22, 2008 at 3:52 AM
  12. fareed
    Joined:
    Jul 2, 2005
    Posts:
    2
    Referrals:
    0
    Sythe Gold:
    0

    fareed Newcomer

    My first program....

    First of all i am sorry for providing uncross-platform libraries since I've never been thought about it in my college. And Swan can you pls tell me what is the function to clear the screen? A cross-platform one of course.

    Thanks 4 the helps.
     
  13. Unread #7 - May 23, 2008 at 6:19 PM
  14. MavFan07
    Joined:
    Dec 18, 2007
    Posts:
    35
    Referrals:
    0
    Sythe Gold:
    0

    MavFan07 Member

    My first program....

    Nice program ;)

    Here is my recommendation:

    Code:
    //Hello Sythe.org
    //My first C++ program
    
    #include <iostream>
    
    using namespace std;
    
    int main ()
    {
    char quit;
    cout << "Hello Sythe.org!" << endl;
    cout << "Press any key to quit: ";
    cin >> quit;
    return 0;
    }
    simple. Some of the other post are good as well, but i'm not sure if you understand the libraries yet, and I don't think you should be using libraries in your code if you don't understand them.
     
  15. Unread #8 - May 23, 2008 at 7:41 PM
  16. Swan
    Joined:
    Jan 23, 2007
    Posts:
    4,957
    Referrals:
    0
    Sythe Gold:
    0
    Sythe's 10th Anniversary Member of the Month Winner

    Swan When They Cry...
    Retired Global Moderator

    My first program....

    Thankyou for clearing that up ;)

    Now that I try it, Conio does not work on my Linux setup as I thought it would. And yes, I was thinking of getch() ;)

    To clear the console output? I've never really had to, and more or less, don't want to. However, you could always Google it. The DOS command for clearing is "cls", where as Linux is just "clear", makes more sense so far as I'm concerned.
     
  17. Unread #9 - May 26, 2008 at 11:25 PM
  18. Nullware
    Joined:
    Jan 30, 2007
    Posts:
    1,761
    Referrals:
    4
    Sythe Gold:
    0

    Nullware Guru

    My first program....

    That is correct but unfortunately on Linux you cannot physically "clear" the terminal window. The clear() function simply pushes all of the current characters up until the window is filled with blank lines. :)
     
  19. Unread #10 - Jun 18, 2008 at 6:00 PM
  20. opensourced
    Referrals:
    0

    opensourced Guest

    My first program....

    Windows is a large cooperate cross platform API because of Wine.
     
  21. Unread #11 - Jun 19, 2008 at 2:13 AM
  22. Swan
    Joined:
    Jan 23, 2007
    Posts:
    4,957
    Referrals:
    0
    Sythe Gold:
    0
    Sythe's 10th Anniversary Member of the Month Winner

    Swan When They Cry...
    Retired Global Moderator

    My first program....

    On my setup it clears the console. Must be the way the developers make it happen.

    opensourcecd, Wine is a 3rd party compatibility layer for people wishing to use Windows programs without actually installing Windows. It isn't perfect, and fails with most corporate software.
     
< Freee *hit@@@@@ | [SOURCE] Command Prompt Pacman in C >

Users viewing this thread
1 guest


 
 
Adblock breaks this site