如何在c++中修复这些错误
How do I fix these errors in c++?
请不要讨厌,因为我还在学习,但我需要帮助将错误排序到这个程序中。
#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;
}
}
}
(这个程序的主要目的是创建一个带有参数的命令行,但我不知道如何解决的两个问题一直存在=第15行和第36行。)
谢谢。
我能看到的唯一错误是,您需要将main移到类的引导。因此,它将是这样的。
#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;
}
此外,我建议你要清楚得多。这样你就可以简化并告诉我们它给你的错误是什么。
相关文章:
- 警告处理为错误这里有什么问题
- "error: no matching function for call to"构造函数错误
- boost::进程间消息队列引发错误
- C++,OpenCV,尝试显示图像时"OpenCV(4.3.0) Error: Assertion failed (size.width>0 && size.height>0)"此错误
- 有关插入适配器的错误。[错误]请求从 'back_insert_iterator<vector<>>' 类型转换为非标量类型
- QT在错误的班级中寻找空位
- vector.resize()中的分配错误
- 代码在main()中运行,但在函数中出现错误
- 释放错误后堆使用
- (C++)分析树以计算返回错误值的简单算术表达式
- Project Euler问题4的错误解决方案
- 我的字符计数代码计算错误.为什么
- 从"int*"强制转换为"unsigned int"会丢失精度错误
- 尝试导入pybind-opencv模块时出现libgtk错误
- CMake项目Boost库错误:Boost/config/compiler/gcc.hpp:165:10:致命错误:cs
- 在某些循环内使用vector.push_back时出现分段错误
- MSVC多行宏编译器错误
- 静态数据成员的问题-修复链接错误会导致编译器错误
- 为什么在运行时没有向我们提供有关分段错误的更多信息?
- 错误:未在此范围内声明'reverse'