Im really new to this but.....

This is a discussion on Im really new to this but..... within the A Brief History of Cprogramming.com forums, part of the Community Boards category; Hello Im really new to this and i want to make a little dos program that will just display a ...

  1. #1
    Registered User
    Join Date
    Jul 2002
    Posts
    27

    Im really new to this but.....

    Hello

    Im really new to this and i want to make a little dos program that will just display a message in a dos window.
    But the only problem is when i run it, it shuts the box down really fast before you can even read it.

    Here is an example code:
    Code:
    #include <iostream.h>
    
    int main()
    {
      cout<<"HEY, you, I'm alive!  Oh, and Hello World!";
      
      return 0;    
    
    }
    Any ideas?

    I need it so it will just keep the box open then also when they click enter it will shut it down.

    Sorry but im new to this only started learning it a few days ago.

    Thank you,
    Chris

  2. #2
    Registered User
    Join Date
    May 2002
    Posts
    317
    Just use cin.get() right before the return 0 statement. This will keep the app open until the user presses any key.

  3. #3
    Registered User
    Join Date
    Jul 2002
    Posts
    85
    besides, you can type the program name in DOS
    for example
    Both of the code(abc.cpp) and exe(abc.exe) file are located in C:\MyCode
    Then choose run at start menu, type cmd or command
    then just type MyCode\abc

    or
    C:\>cd MyCode
    C:\MyCode>abc

    The result is visible and no extra code is required.
    Please note that it is case-insensitive in DOS

  4. #4
    PC Fixer-Upper Waldo2k2's Avatar
    Join Date
    May 2002
    Posts
    2,001

    besides cin.get()

    you can also:
    Code:
    #include <conio.h>
    
    ...
    cin>>whatever;
    cout<<whatever<<endl;
    getch();
    return 0;
    }
    
    //OR
    
    #include <stdlib.h>
    
    ...
    cin>>whatever;
    cout<<whatever<<endl;
    system("PAUSE");
    return 0;
    }
    whichever you want to do, getch waits for a user to press "any key" same with pause
    PHP and XML
    Let's talk about SAX

  5. #5
    Registered User VBprogrammer's Avatar
    Join Date
    Mar 2002
    Posts
    175
    lol, or just run it from the command prompt...
    VC++ 6

  6. #6
    I am the worst best coder Quantrizi's Avatar
    Join Date
    Mar 2002
    Posts
    644

    Re: besides cin.get()

    Originally posted by Waldo2k2

    whichever you want to do, getch waits for a user to press "any key" same with pause
    Actually, getch() doesn't output any messages, while pause outputs "Press any key to continue..."

  7. #7
    Seven years? civix's Avatar
    Join Date
    Jul 2002
    Posts
    605
    put a system("PAUSE"); right before the return 0; but make sure you have windows.h included!

  8. #8
    I am the worst best coder Quantrizi's Avatar
    Join Date
    Mar 2002
    Posts
    644
    u don't need windows.h, just stdlib.h (or cstdlib) for system("PAUSE");

  9. #9
    Registered User
    Join Date
    Jul 2002
    Posts
    27
    Ok got that working...... how can i make it so i can have writing on a new line?

  10. #10
    Registered User
    Join Date
    Jul 2002
    Posts
    27
    Also what i would like this thing to do is display one line first then about 10 seconds after display the second line then another 10 seconds after display another line.

    Can this be done?

  11. #11
    Registered User
    Join Date
    Jul 2002
    Posts
    85
    Originally posted by ChrisMUK
    Ok got that working...... how can i make it so i can have writing on a new line?
    cout<<"\n"; // a new line
    printf("\n"); // also a new line

  12. #12
    Registered User
    Join Date
    Jul 2002
    Posts
    27
    Ok got the line thing working.

    Now any idea on the thing where it will display different lines at different times?

  13. #13
    Registered User
    Join Date
    May 2002
    Posts
    317
    Try using sleep(timeout); where timeout is an int representing the number of milliseconds you wish to wait.

  14. #14
    Registered User
    Join Date
    Jul 2002
    Posts
    27
    Can you just show me an example of what you mean. As i said im new to this and am only just learning it.

  15. #15
    Registered User
    Join Date
    May 2002
    Posts
    317
    Ask and ye shall recieve
    Code:
    #include<iostream>
    #include<windows.h>
    #include <conio.h>
    
    using namespace std;
    
    
    int main(void){
    	cout<<"This is my first line";
    	Sleep(3000);	//wait for three seconds
    	cout<<endl<<"this is my second line of text";
    	Sleep(3000);
    	cout<<endl<<endl<<"This is my final line of text";
    	cin.get();
    	return(0);
    }

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21