Skip to content
TheChatArchiveThe Chat Archive
gpt-3.5-turbo-0613· OpenAIAi2 WildChat-4.8M (AI2)

main.cpp:13:18: error: no match for ‘operator>>’ (operand types are ‘std::istream’ {aka…

  1. User

    main.cpp:13:18: error: no match for ‘operator>>’ (operand types are ‘std::istream’ {aka ‘std::basic_istream’} and ‘std::vector’) 13 | std::cin >> a; Сам код:

    #include #include

    int main() { int n; std::vector a; std::vector res(200000, 0); std::cin >> n;

    for (int i=0; i < n; i++)
    {
        std::cin >> a;
        res[a] = i;
    }
    
    int mn = 1000000000, iMn = -1;
    for(int i=0; i < res.size(); i++)
    {
        if (res[i] < mn)
        {
            mn = res[i];
            iMn = i;
        }
    }
    std::cout << iMn;
    
    return 0;
    

    }

  2. Assistant

    The error is because you are trying to use the operator>> on a std::vector<int> object, which is not defined. The operator>> is only defined for basic types like int, float, etc.

    To fix the error, you need to read the elements of the vector one by one using a loop:

    for (int i = 0; i < n; i++)
    {
        int x;
        std::cin >> x;
        a.push_back(x);
        res[x] = i;
    }
    

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.