Thread: here we go again

  1. #1
    Registered User
    Join Date
    Jan 2003
    Posts
    6

    here we go again

    #include <iostream.h>
    int main () {
    int thisisanumber;
    cout <<"please enter a number";
    cin >> thisisanumber;
    cout <<"you entered: " <<thisisanumber;
    return 0;
    }

    the file does not want to run

  2. #2
    First of all use code tags when posting code. Second of all use this:

    Code:
    #include <iostream>
    using namespace std; //remove the std:: infront of the cout's and the cin and remove the next line if using this
    using std::cout;  //only does cout, remove the above line and std:: ONLY that are infront of cout's if using this
    
    int main()
    {
        int thisisanumber;
        std::cout << "Enter a number: ";
        std::cin >> thisisanumber;
        std::cout << "\nYou typed " << thisisanumber;
        return 0;
    }

  3. #3
    Registered User
    Join Date
    Apr 2002
    Posts
    362
    Actually, it does run. Depends on your compiler, though. MSVC++ automatically stops at the end of the execution.

    Borland, and others, need to be "forced" to stop with a "pause" statement of some nature. If you're getting a "quickie" screen and, then back to your code, you need to pause the display. (Leaving that up to you to discover. )

    Munkey01 is right. Better to lose the non-standard code and "upgrade" to the standard.

    As an addendum, if you use 'using namespace std;', then write your code as you would with the deprecated language.

    If you utilize 'using std::cout', for example, you can write the code as you normally would for 'cout' within main(). However, you'll find yourself writing a lot of 'using std::whatever' statements prior to main() because you'll have to include 'using...' statements for all of the standard language keywords.

    Munkey01 illustrates, within main(), how to write out the standard code without doing 'using namespace std;', or without including a lot of 'using std::*' statements.

    Kind of a personal preference. If you like to type, use std::*keyword* within main().

    Lots of arguments, pro and con, which I don't intend to get into. (It's been done. )

    -Skipper
    "When the only tool you own is a hammer, every problem begins to resemble a nail." Abraham Maslow

  4. #4
    Registered User
    Join Date
    Jan 2003
    Posts
    6
    i changed from doing a windows apllication to doing a consult app
    now it seems to work i still have to figure out how to get the display to stop closing so quickly.

  5. #5
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    <stdlib.h>


    at end of program before return:

    system("pause");

Popular pages Recent additions subscribe to a feed