views:

68

answers:

3

I am learning C++ in school now. Currently using C++ with codeblocks on my windows vista laptop. I noticed whenever I try to use functions from imported classes from the Clibrary I get an error in the console.

" 'hi' is not recgonized as internal or external command, operable command or batch file "

My code looks like this ...

#include <iostream>
#include <cstdlib>  

using namespace std;

int main()
{
    system("hi");
    return 0;
}

Just something simple you can see, however I am getting that error. I can use the iostream fine, I have tested the io include and that works... is there something else I need to install to be able to use the cstdlib?

Thank you, Zach Smith

+3  A: 

The error is exactly what it looks like: you're trying to execute with system a command that simply does not exist, so you'll get just the same error if you typed hi at a command prompt (codeblocks has nothing to do with it). Try using e.g. system("echo hi") or any other command that does exist and your results might be better.

Alex Martelli
That does work! Thank You!I am curious because the code I gave you is exactly what I copied out of my text when "playing around" (The book is Bruce Eckle's thinking in C++, for the curious). Interesting.Anyway, Thank You!
Zach Smith
The example you're referencing is in chapter 2, yes? Notice that that sample is under the heading "**Calling other programs**"
greyfade
+6  A: 

system() in cstdlib runs another command on the system. Unless there's a hi.exe on your path, this is going to fail. It looks as if you want to write "hi" to stdout, in which case your code should be:

#include <iostream>

using namespace std;

int main()
{
   cout << "hi" << endl;
   return 0;
}
Grant Limberg
A: 

If you want to use iostream, try:

cout << "hi" << endl;
jeffamaphone