解决“嗨”问题未被识别为内部或外部命令...”使用 C++ 时出错Windows Vista 上有代码块吗?
我现在在学校学习C++。目前在我的 Windows Vista 笔记本电脑上使用带有代码块的 C++。我注意到每当我尝试使用从 Clibrary 导入的类中的函数时,我都会在控制台中收到错误消息。
“‘hi’不被识别为内部或外部命令、可操作命令或批处理文件”
我的代码看起来像这样......
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
system("hi");
return 0;
}
只是一些简单的东西你可以看到,但是我收到了这个错误。我可以很好地使用 iostream,我已经测试了 io include 并且可以工作...我还需要安装其他东西才能使用 cstdlib 吗?
谢谢你, 扎克·史密斯
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
cstdlib 中的 system() 在系统上运行另一个命令。除非您的路径上有 hi.exe,否则这将会失败。看起来好像您想将“hi”写入标准输出,在这种情况下您的代码应该是:
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:
该错误正是它看起来的样子:您尝试使用
system
执行一个根本不存在的命令,因此如果您输入hi 在命令提示符下(codeblocks 与它无关)。尝试使用例如
system("echo hi")
或任何其他确实存在的命令,您的结果可能会更好。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 typedhi
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.如果你想使用 iostream,请尝试:
If you want to use iostream, try: