我是 C++ 的新手,我正在尝试制作我自己的“cmd”。仍然收到错误:“|11|错误:带有值的返回语句,在返回‘void’的函数中 [-fpermissive]|”... 请帮助:(
代码在这里:
#include <iostream>
#include <string>
using namespace std;
void cmd(int command)
{
if (command == login)
{
cout << "Prikaz login neni k dispozici!";
return 0;
}
else
{
cout << "Prikaz ";
cout << command;
cout << " neni znamy!";
return 0;
}
}
int main()
{
cout << "Zadejte prikaz: ";
cin << command;
cmd(command);
return 0;
}
最佳答案
不知道您到底打算做什么,但下面的程序应该可以工作。您只是没有正确声明整数变量。
#include <iostream>
#include <string>
using namespace std;
int cmd(string command)
{
if (command == "login")
{
cout << "Prikaz login neni k dispozici!";
return 0;
}
else
{
cout << "Prikaz ";
cout << command;
cout << " neni znamy!";
return 0;
}
}
int main()
{
string command; /* Define String */
cout << "Zadejte prikaz: ";
cin >> command; /* Input */
cmd(command);
return 0;
}
关于C++ 如果在函数中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34977732/