首页 > 解决方案 > 没有运算符匹配这些操作数;操作数类型为: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]

标签: c++

解决方案


您正在尝试读取字符串文字的输入。

如果要在输入字符串test2的情况下输出字符串test,请执行以下操作

#include <iostream>
#include <string>
using namespace std;

int main() {
    string s;
    cin >> s;
    if (s == "test") {

        cout << "test2";
    }

    system("pause");
    return 0;
}

推荐阅读