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

Feb 8, 2018 at 8:27pm
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
Feb 8, 2018 at 8:31pm
...
does this work?

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

Feb 8, 2018 at 8:49pm
that worked
Feb 8, 2018 at 8:54pm
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.
Feb 8, 2018 at 8:58pm
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.....
Feb 8, 2018 at 8:58pm
What compiler do you use?
Feb 8, 2018 at 9:00pm
Visual studio 2017
Feb 8, 2018 at 10:28pm
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 Feb 8, 2018 at 10:29pm
Feb 8, 2018 at 11:20pm
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.