cin.get() / system("pause")

johanjohan's Avatar
Go4Expert Member
I used code to create that littl box for the code to go into, but if it doesnt work then ill try again



Ive used both cin.get() and system("pause") to let the program run while keeping the window open. In both cases the program runs one line and then stops. I dont understand why their stopping the program. Im using a dev compiler.

thanks

Code: cpp
#include<iostream>
using namespace std;
int main()
{
    int counter;
    for(counter=1; counter < 101; counter++);
    cout << "is this working" <<endl;
cin.get();
return 0;
}
DaWei's Avatar, Join Date: Dec 2006
Team Leader
You're not clear. Runs one line? Which line? What do you mean, stops?

Your for loop does nothing but count. That's an invisibly short delay. Is the cout working?
johanjohan's Avatar
Go4Expert Member
when I run the progra,, it prints "is this working" , just one time. below that it says please press any key to continue, when I hit the enter button the whole screen disapears.

Its suppose to print out "is this working 100 times because the counter is set at 1. But it doesn't

I checked the counter, cout, the loop and the whole program and cant find a flaw.

Yet it doesnt work
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
You have a semicolon after the for loop which means the cout statement is not within the loop but outside the loop.
johanjohan's Avatar
Go4Expert Member
thank you
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Quote:
Originally Posted by johanjohan
thank you
My pleasure.