system("pause") won't work for me

error: 'system' was not declared in this scope

I don't know why, please help me, thank you in advance.

PS: I use Code::Blocks10.05, what do you guys use?
Last edited on
It's because of your compiler. If I am correct, "system("PAUSE");" only works on Windows computers.

If you are using <iostream>, try:
 
cin.get();
@Cuddly

cin.get(); works for me, but why 'system' won't?

My OS is Windows 7 SP1.
error: 'system' was not declared in this scope

means that your compiler has never heard of such a thing as system, because you have not declared it. You can include the declaration by including the cstdlib header, i.e.
 
#include <cstdlib> 


Use of system is frowned upon because it asks the shell you are executing in to run some other programme for you. You have no guarantee that the other programme exists, and no guarantee that it does what you want.

If you just want to pause your programme, do as the Kitten says, or alternatively if you just want the console window to remain visible, run your programme from a console.
Last edited on
There's no need to pause the program if you run it from C::B since it will pause it for you ( you can toggle this on the project settings )
Problem solved. Thank you, @Cuddly, @Moschops.
@Bazzy

But it won't pause for me. What is the exact location of the setting?
Project Properties > Build Targets > Pause when execution ends
@Bazzy

I see, it won't pause for me because what I've been editing is a file not a project. Thank you very much.
isn't it has to be capital?

SYSTEM("PAUSE");

CMIIW
SYSTEM() does not exists as function and Windows commands are not case sensitive ( so "pause" and "PAUSE" should be the same )
Topic archived. No new replies allowed.