#### Archived

This topic is now archived and is closed to further replies.

# System pause messing my program?

This topic is 5577 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi everybody. How''s eery1 feeling today? As y''all know in the weekend I was having trouble with borland. Well, after 36 hours, I successfully got my compiler working 8-). I''m reading the book c++ in 21 days and i''m on day 2. I was to write a program using new lines and just pointless facts. When I execute it it flashes on the screen, so I add the system("PAUSE"); code, and I get the error "17 programmer.cpp implicit declaration of function int system(...)''". Here''s the code...
// Listing 2.2 using cout

#include <iostream.h>

int main()
{
cout << "Hello There.\n";
cout << "Here is 5: " << 5 << "\n";
cout << "The manipulator endl writes a new line to the screen." <<
endl;
cout << "Here is a very big number:\t" << 70000 << endl;
cout << "Here is the sum of 8 and 5:\t" << 8+5 << endl;
cout << "here''s a fraction:\t\t" << (float) 5/8 << endl;
cout << "And a very very big number:\t" << (double) 7000 * 7000 <<
endl;
cout << "Jamie is a c++ programmer!\n";
system("PAUSE");
return 0;
}


##### Share on other sites
You have to include the header file that contains the system function - which is <cstdlib> (or stdlib.h if that''s not available...)

#include <cstdlib>// or #include <stdlib.h> if the above gives problems 

Do that near the same place that you included iostream.h (incidentally, you should be using
#include <iostream> 
followed by
using namespace std; 
, but that''s another story for another day.

See here: http://www.cplusplus.com/ref/cstdlib/ and find the ''system'' function.

##### Share on other sites
Thanks, but it appearsto have stopped working > . Sorry bout this...

// Listing 2.2 using cout#include <cstdlib>using namespace std;int main(){  cout << "Hello There.\n";  cout << "Here is 5: " << 5 << "\n";  cout << "The manipulator endl writes a new line to the screen." <<  endl;  cout << "Here is a very big number:\t" << 70000 << endl;  cout << "Here is the sum of 8 and 5:\t" << 8+5 << endl;  cout << "here's a fraction:\t\t" << (float) 5/8 << endl;  cout << "And a very very big number:\t" << (double) 7000 * 7000 <<  endl;  cout << "Jamie Smith is a c++ programmer!\n";  int  system ( const char * PAUSE );  return 0;}  

It gives me this error.
"19 c:\docume~1\jamie\desktop\listings\2.2\progra~1.cpp
implicit declaration of function int system(...)'"

Tried cstdlib.h and cstdlib- neither worked, just created 8 errors.

[edited by - fivepointo on October 16, 2002 11:07:12 AM]

##### Share on other sites

  #include <cstdlib> // notice added line here#include <iostream>using namespace std;int main(){  cout << "Hello There.\n";  cout << "Here is 5: " << 5 << "\n";  cout << "The manipulator endl writes a new line to the screen." <<  endl;  cout << "Here is a very big number:\t" << 70000 << endl;  cout << "Here is the sum of 8 and 5:\t" << 8+5 << endl;  cout << "here''s a fraction:\t\t" << (float) 5/8 << endl;  cout << "And a very very big number:\t" << (double) 7000 * 7000 <<  endl;  cout << "Jamie Smith is a c++ programmer!\n";  system("PAUSE");  return 0;}

##### Share on other sites
Long time no speak, mockjock.

Thanks, it's working. Appreciated. Thanks to the both of ya.

[edited by - fivepointo on October 16, 2002 11:11:15 AM]

##### Share on other sites
Ah, just saw your edit - that won't work! What happens is that you have to *prototype* your functions first before you use them. This lets the compiler check that you're using them correctly (so, for example, you don't pass a std::string where it expects an int, or something).

The prototype is written as the return type, function name, then parameters (if any):

int myFunc(int param1);

This is fleshed out later by writing an actual definition:

int myFunc(int param1){    return param1 * 2;}

The compiler has to know about functions before you can use them. The declaration (aka "prototype") goes in a header file, which you including using #include. The definition goes in a cpp file - but usually you don't include them.

To use the function, you must first #include the appropriate header file (in this case, ). This lets the linker know that the function exists.

You then *call the function in code* by simply stating its name plus any parameters.

For example, "system" expects a char* parameter (a cheesey string). This means that you can call it by stating its name plus a string, in brackets. Like this: system("PAUSE");. Note that this is different from declaring it - it's already been prototyped elsewhere, so you can simply use it once it's included.

Minor edit: fixed typo + correct (I said "definition" = prototype, but I meant "declaration" = prototype).

[edited by - Alimonster on October 16, 2002 11:23:02 AM]

##### Share on other sites
What can i say, you know your stuff . I thought you only used delphi though?

##### Share on other sites
Nah, it''s what I like, but I know plenty of other languages. The more languages you learn, the easier they get . It helps to have several tools and to pick the best one - there are some problems that are better suited to C++, Delphi, Java... pick the one that works for you.

Never stop at one language, though. It limits your thinking. Once you''ve got a grip on C++, learn other ones (Java would be easy). Of course, that''s in the future .

##### Share on other sites
Coolio. I was actually thinking of stopping C++ right now and learning java, as i''ve heard many ppl(including you) say it''s easier than c++. C++ is my first programming language, part from html(but that aint very good as a prog introduction, cause there r no procedures or functions or anything).

##### Share on other sites
quote:
Original post by fivepointo
Thanks, but it appearsto have stopped working > . Sorry bout this...

// Listing 2.2 using cout#include <cstdlib>using namespace std;int main(){  cout << "Hello There.\n";  cout << "Here is 5: " << 5 << "\n";  cout << "The manipulator endl writes a new line to the screen." <<  endl;  cout << "Here is a very big number:\t" << 70000 << endl;  cout << "Here is the sum of 8 and 5:\t" << 8+5 << endl;  cout << "here''s a fraction:\t\t" << (float) 5/8 << endl;  cout << "And a very very big number:\t" << (double) 7000 * 7000 <<  endl;  cout << "Jamie Smith is a c++ programmer!\n";  int  system ( const char * PAUSE );  return 0;}

It gives me this error.
"19 c:\docume~1\jamie\desktop\listings\2.2\progra~1.cpp
implicit declaration of function `int system(...)''"

Tried cstdlib.h and cstdlib- neither worked, just created 8 errors.

[edited by - fivepointo on October 16, 2002 11:07:12 AM]

you forgot iostream

##### Share on other sites
Yeah mockjock already gave me the solution. Thx neways

##### Share on other sites
quote:
Original post by fivepointo
Coolio. I was actually thinking of stopping C++ right now and learning java, as i've heard many ppl(including you) say it's easier than c++. C++ is my first programming language, part from html(but that aint very good as a prog introduction, cause there r no procedures or functions or anything).

It's much of a muchness, to be honest. Java does present some obstacles - for example, you're forced into using object oriented programming. That can be a little annoying to grasp, especially if you've not done things the easy (procedural) way. You'll learn some things more quickly (classes, for example) with Java because you're forced to use it, but sometimes that extra OO can get in the way.

Garbage collection is a nice feature when it works. It means that you don't have to worry about deallocating any objects that you create.

If you want to use Java, I won't stand in your way. However, it would be a little bit of a shame if you've gone and got books + spent so long on the compiler . If you want to stick with C++ then there are plenty of people who know it. If you want Java then there's a forum at this site too.

You can get Java from over here: http://java.sun.com/j2se/1.4/download.html (I think). It's a fairly big download though. Also, you need to get your hands on an IDE to do your stuff. People can't code effectively in Notepad for a long time.

Check out the Java forum here - there are always a few questions about the IDE. Eclipse, JBuilder and JCreator and often stated as good ones (plus some others).

If you want a tutorial, check out http://developer.java.sun.com/developer/onlineTraining/. Choose either the Java language tutorial or the Swing tutorial (which is the standard GUI toolkit for Java, replacing the older AWT).

However, you'll be looking at console apps for a while even if you use Java. It's entirely up to you (and quite possibly an excuse to start another language war, w00t!).

[edited by - Alimonster on October 16, 2002 11:34:19 AM]