c++ - 没有运算符匹配这些操作数;操作数类型为:std::istream >> const char [5]
问题描述
我是编码新手(昨天开始),我正在尝试做这件事,当我输入特定内容时,我会得到一个自定义输出。
#include <iostream>
using namespace std;
int main()
{
if (cin >> "test") {
cout << "test2";
}
system("pause");
return 0;
}
C++ 没有操作符匹配这些操作数操作数类型是:std::istream >> const char [5]
解决方案
您正在尝试读取字符串文字的输入。
如果要在输入字符串test2
的情况下输出字符串test
,请执行以下操作
#include <iostream>
#include <string>
using namespace std;
int main() {
string s;
cin >> s;
if (s == "test") {
cout << "test2";
}
system("pause");
return 0;
}
推荐阅读
- angular - 使用 Mat-Select 过滤 Observable 数组
- reactjs - 将 Button 组件传递给 Bootstrap Tab 组件的 Title 属性
- python - 熊猫重命名列名
- jaxb - 由于 580 次 IllegalAnnotationExceptions 创建 JAXB Marshaller 时出现 jbpm 错误
- firebase - 将公共之外的根文件夹添加到托管 Firebase
- powerbi - 如何使用 DAX 中的键过滤的时间输入和超时来制作连贯的 IF 语句
- for-loop - 在 systemverilog 中实现 for 循环
- sql - SQL Total Distinct Count on Group By Query
- c - 我正在尝试对字符 z(ASCII 122)执行凯撒移位。如何给它“更多空间”以防止它溢出超过 127?
- django - Django-cms,模板中的子变量,页面导航在较新版本中不显示