Server Help

Non-Subspace Related Coding - probblem with c++

hellzlaker - Thu Nov 16, 2006 6:35 pm
Post subject: probblem with c++
Code: Show/Hide
// my first program in C++

#include <iostream>
using namespace std;

int main ()
{
  cout << "Hello World!";
  return 0;
}


when i enter it in c++ it compiles it fine, but when i run it it closes... need help

also all of other stuf that i compile doesnt work like
Code: Show/Hide
// my second program using variables

#include <iostream>
using namespace std;

int main ()
{
    //telling variables
    int a,b;
    int result;
   
    //variable values and process
    a = 5;
    b = 2;
    a = a + 1;
    result = a - b;
   
    //show the result
    cout<< result;
   
    //turn off the program function
    return 0;
}

BDwinsAlt - Thu Nov 16, 2006 7:22 pm
Post subject:
Code: Show/Hide

// my first program in C++

#include <iostream>
#include <stdlib.h> // Used for system commands like pause
using namespace std;

int main ()
{
  cout << "Hello World!";
  system("pause");    // Pauses the console screen.
  return 0;
}


Another way to do it is to check for input after the program is done running so they have to push enter before it closes the program.

Also after 'cout' space between the 'cout' and '<<' so cout<< should be cout <<.
hellzlaker - Thu Nov 16, 2006 7:24 pm
Post subject:
is it only my computer that does that? because last year when i started c++ i dint need the pause function..
BDwinsAlt - Thu Nov 16, 2006 7:26 pm
Post subject:
I'm pretty sure it depends on the compiler. With Dev C++ I had to, with Visual Studio .NET 2003 I don't have to.
Muskrat - Thu Nov 16, 2006 9:27 pm
Post subject:
ya know if you ran it from a command line it wouldn't disappear, that's why it dosent close in visual studio either....
BDwinsAlt - Thu Nov 16, 2006 9:32 pm
Post subject:
For some reason people like to just click on icons. Just use a simple batch file in that case to execute it.
Muskrat - Thu Nov 16, 2006 10:46 pm
Post subject:
Or he could write programs which either A. don't need input or output in a command line or B. has an input loop that will not end the program until he tells it to.
Cyan~Fire - Fri Nov 17, 2006 12:31 pm
Post subject:
System commands suck. If you really want to wait for an enter key at the end or something, use cin.getc() or whatever it's called. (The getchar() equivalent.) You might want to call cin.flush() beforehand, too, to make sure it has to prompt for input.
Bak - Fri Nov 17, 2006 2:07 pm
Post subject:
If you're using MSVC++, do Debug-> Run without Debugging (Ctrl + F5) instead of Debug -> Debug.
All times are -5 GMT
View topic
Powered by phpBB 2.0 .0.11 © 2001 phpBB Group