Jump to content
  • Advertisement

Archived

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

fivepointo

System pause messing my program?

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

If you intended to correct an error in the post then please contact us.

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;
}
 
Can some1 please help. Thankyou all for your help, I really appreciate it. My AIM SN is rarebreed335. Can some1 please help, I need major help. I want to understand this before I move on. Thanks alot.

Share this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!