[英]How do I fix these errors in c++?
Please don't hate as I am still learning but I need help sorting the errors to this program.请不要讨厌,因为我还在学习,但我需要帮助整理这个程序的错误。
#include <iostream>
#include <string>
#include "ConCommand.h"
using namespace std;
struct Command
{
string usage;
string command;
} command;
void SayCommand(string in)
{
cout << in.substr(command.length() + 1, in.length()) << endl;
}
int main()
{
string in;
struct Command command1;
command1.usage = "say <MESSAGE>";
command1.command = "say";
while (true)
{
cout << ">>> ";
getline(cin, in);
if (in == "")
{
cerr << "Please enter a command!" << endl;
}
ConCommand(in, command1.usage, command1.command, SayCommand());
}
return 0;
}
void ConCommand(string in, string usage, string command, void (*execFunc)(string))
{
if (in.substr(0, command.length()) == command)
{
if (in.substr(command.length(), in.length()) != "")
{
//cout << in.substr(command.length() + 1, in.length()) << endl;
execFunc(in);
}
if (in.substr(command.length(), in.length()) == "")
{
cout << "Usage: " + usage << endl;
}
}
}
(The main aim of this program is to create a command line with arguments, but two problems that I have no clue how to fix keep being there = line 15 & line 36.) (这个程序的主要目的是创建一个带参数的命令行,但我不知道如何解决的两个问题一直存在=第 15 行和第 36 行。)
Thank you.谢谢你。
The only error I can see is that you need to move main to the boot of the class.我能看到的唯一错误是您需要将 main 移动到类的引导。 Thus it will look like this.因此它看起来像这样。
#include <iostream>
#include <string>
#include "ConCommand.h"
using namespace std;
struct Command
{
string usage;
string command;
} command;
void SayCommand(string in)
{
cout << in.substr(command.length() + 1, in.length()) << endl;
}
void ConCommand(string in, string usage, string command, void (*execFunc)(string))
{
if (in.substr(0, command.length()) == command)
{
if (in.substr(command.length(), in.length()) != "")
{
//cout << in.substr(command.length() + 1, in.length()) << endl;
execFunc(in);
}
if (in.substr(command.length(), in.length()) == "")
{
cout << "Usage: " + usage << endl;
}
}
}
int main()
{
string in;
struct Command command1;
command1.usage = "say <MESSAGE>";
command1.command = "say";
while (true)
{
cout << ">>> ";
getline(cin, in);
if (in == "")
{
cerr << "Please enter a command!" << endl;
}
ConCommand(in, command1.usage, command1.command, SayCommand());
}
return 0;
}
Also I would recommend being much much more clear.此外,我建议要清楚得多。 Such that you simplify and tell us what the error that it is giving you is.这样您就可以简化并告诉我们它给您带来的错误是什么。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.