解决"'hi'不被识别为内部或外部命令..."在Windows Vista上使用带有代码块的C++时出错?

Zac*_*ith 0 c++ codeblocks

我现在正在学校学习C++.目前在我的windows vista笔记本电脑上使用带有代码块的C++.我注意到每当我尝试使用Clibrary导入的类中的函数时,我在控制台中都会出错.

"'hi'未被记录为内部或外部命令,可操作命令或批处理文件"

我的代码看起来像这样......

#include <iostream>
#include <cstdlib>  

using namespace std;

int main()
{
    system("hi");
    return 0;
}    
Run Code Online (Sandbox Code Playgroud)

只是简单的你可以看到,但我得到了这个错误.我可以使用iostream很好,我已经测试了io include并且有效......我需要安装其他东西以便能够使用cstdlib吗?

谢谢你,扎克史密斯

Gra*_*erg 6

cstdlib中的system()在系统上运行另一个命令.除非你的路径上有一个hi.exe,否则这将失败.看起来好像你想写"hi"到stdout,在这种情况下你的代码应该是:

#include <iostream>

using namespace std;

int main()
{
   cout << "hi" << endl;
   return 0;
}
Run Code Online (Sandbox Code Playgroud)