system("pause") not owrking (visual Studio)

when i do below

1
2
3
4
5
6
7
8
#include<iostream>
using namespace std;
int main()
{
    cout << "hello"<< endl;
    system("pause");
    return 0;
}

i get "hello" and no "press any key to exit....". The close button does not work or the stop soft key work, it closes on its own. PLz help
...
does this work?

make a text file,
type the word pause in it
rename it name.bat
double click it.

that worked
not owrking
PLz help

It's like you CantSpel. Get it?
Sorry.

From my experiences, I think you may have to include another library. I'm not too sure. If you're on Windows, this should work... Interesting.
yeah the "press any key came up...." came up after like 10 min. its starting to affect other computers in the class room, so it was probably something IT did.....
What compiler do you use?
Visual studio 2017
Hello CantSpel,

If I remember correctly "system" needs the header file "stdlib.h". Luckily this is eventually included through "iostream" an was not a problem in my VS 2015.

Not sure what VS 2017 has made in regards to the C header files, but "stdlib.h" may no longer be included through "iostream" and may not even be available.

Not being familiar with your clas computer or network I find it curious that other computers are being affected.

In the end "system" anything should be avoided in favor of something else. You could try using:
1
2
std::cout << "\n Press Enter to continue: ";
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');  // <--- Requires header file <limits>. 

Hope that helps,

Andy
Last edited on
In VS it should suffice to press Alt + F7, open the 'Linker'-Tab,

Select the 'Platform'-Tab: Choose either all Platforms, or Active(Win32), or X64
Select the 'SubSystem'-Tab: Console (/SUBSYSTEM:CONSOLE)

-

Pay attention that the Solution Platform (The small dropdown window next to Debug dropdown window in the menu-bar) is set accordingly to X86 or X64.

-

Having your project set-up that way, you will not need the system("Pause"); or cin.get() etc. The console window will remain open until pressing a key.
Topic archived. No new replies allowed.