程序告诉我,即使它们明显匹配,参数也不匹配
Program is telling me arguments don't match even when they clearly do
>图片 所以我的C++程序连接到我的服务器以下载并安装最新版本。当更新可用时,它将下载安装程序.exe文件,然后启动它。安装程序.exe安装新文件,然后使用"-rs"参数启动新程序。客户端/服务器端的更新代码运行良好,但由于某种原因,程序没有选择"-rs"参数。它告诉我没有指定"-rs",这很奇怪,因为如果我在 argv1 <<键入 std::cout,它会将 -rs 打印到控制台。我什至尝试制作一个快捷方式,使用"-rs"启动程序,它仍然说 -rs 不等于 -rs。
if (argc == 2)
{
std::cout << "There are 2 arguments." << std::endl;
std::cout << "'" << argv[1] << "' is the second argument." << std::endl;
if (argv[1] != "-rs")
{
std::cout << "'" << argv[1] << "' is not equal to '-rs' WTF?" << std::endl;
}
}
您正在将单个字符指针与整个字符数组进行比较,尝试给 argv != "-rs" 您的条件语句是错误的。是的,如果您采用命令行参数,那么您需要给出 2 个要比较的索引,例如 argv[index][index]
std::cout << "There are 2 arguments." << std::endl;
std::cout << "'" << argv[1] << "' is the second argument." << std::endl;
if (argv != "-rs")
{
std::cout << "'" << argv[1] << "' is not equal to '-rs' WTF?" << std::endl;
}
或
char argv[2][4] = {"-ws","-rs"};
std::cout << "There are 2 arguments." << std::endl;
std::cout << "'" << argv[1] << "' is the second argument." << std::endl;
if (argv[1] != "-rs")
{
std::cout << "'" << argv[1] << "' is not equal to '-rs' WTF?" << std::endl;
}
相关文章:
- Qt SQLite没有查询或参数计数不匹配
- 模板参数推导失败,函数参数/参数不匹配
- C++模板/别名 - 模板参数列表中参数 1 处的类型/值不匹配
- 错误:"模板<类_Tp,类_Dp>类 std::unique_ptr"的模板参数列表中参数 1 的类型/值不匹配
- 为什么使用不匹配的参数调用重载函数仍然有效
- 没有函数模板的实例与我不知道为什么的参数列表匹配
- 程序告诉我,即使它们明显匹配,参数也不匹配
- 模板参数'(type)0'与'EnumValue'不匹配
- 将构造函数添加到boost.python子类导致参数不匹配错误
- LPCSTR和wchar_t问题.由于参数不匹配,导致链接器错误
- 为什么可以将std::bind分配给参数不匹配的std::函数
- C++中的默认参数不匹配
- 布尔类型的参数不匹配
- 方法调用C++/数字参数不匹配
- NULL 与模板参数不匹配?
- C++ - 模板 + 'using' 子句 - 参数不匹配错误
- c++代码中的参数不匹配错误
- QT5迁移和Boost:if.hp:宏参数不匹配错误
- 为什么函数原型中的参数数量与定义中的参数不匹配
- 为什么我的函数参数不匹配