"No instance of constructor" 所有标准数据类型(映射、向量、堆栈等)的错误

"No instance of constructor" error for all std data types (map, vector, stack, etc.)

我 运行 遇到了一个奇怪的问题。我认为这可能是由于 Mac 有问题,但我不确定。本质上,我在我的 windows 笔记本电脑上解决了这个 Leetcode 问题,并将代码推送到我的 github 存储库。然后我稍后在 mac 上获取了该代码,并且在尝试初始化任何 std:: 数据类型(例如映射、向量或堆栈)时突然出现此错误。这很奇怪,因为我以前从未收到过这个错误,并且使用那些 类 到目前为止效果很好。我不太确定发生了什么,有人可以指出正确的方向来解决这个问题吗?我在下面附上了显示错误的屏幕截图。我一直在环顾四周,找不到其他有类似问题的人。谢谢!

#include <vector>
#include <map>
#include <iostream>
#include <cstdlib>
#include <string>
#include <stdlib.h>

using namespace std;
/**
 * @brief Rules:
 * 1. Open brackets must be closed by the same type of brackets.
 * 2. Open brackets must be closed in the correct order.
 * 
 * Leetcode Challenge can be found here: https://leetcode.com/problems/valid-parentheses/
 */
//correlate the opening character with the closing character.

map<char, char> legend {{'{','}'},{'(',')'},{'[',']'}};//Error
vector<int> vect{0,2,3,4,5};//Error

bool isValid(string s) 
{
    //if s is odd then we know a bracket hasn't been closed. Return false.
    if (s.length() % 2 != 0)
    {
        return false;
    }

    vector<char> stack; //initiate our stack where we'll store opening characters "(, {, ["
    bool stackIsModified = false; //We need to make sure an opening character has been added to the stack at least once.

    for (int i = 0; i < s.length(); i++)
    {
        if (s[i] == '{' || s[i] == '[' || s[i] == '(')//Check and see if s[i] is an opening character.
        {
            stackIsModified = true;
            stack.push_back(s[i]);
            cout << s[i] << endl;
        }
        
        else if(stack.size() != 0) //See if s[i] is a closing character.
        {
            if (legend[stack.at(stack.size() - 1)] == s[i])
            {
                stack.pop_back();
            }
            else //If s[i] is a closing character that doesn't match the corresponding opening character. Ex: "{)"
            {
                return false;
            }
        }
        else //If s[i] isn't an opening character and the stack is empty then we know there's a mismatch, return false.
        {
            return false;
        }
    }

    if (stack.size() > 0 || !stackIsModified) //Make sure the stack doesn't have remaining opening characters and that the stack has been changed at least once.
    {
        cout << stackIsModified << endl;
        return false;
    }
    
    return true;
}

int main() 
{

    cout << isValid("()))") << endl;//Random test case.
    return 0;
}

这些是我收到的错误(在旁边有错误注释的两行):

no instance of constructor "std::__1::map<_Key, _Tp, _Compare, _Allocator>::map [with _Key=char, _Tp=char, _Compare=std::__1::less<char>, _Allocator=std::__1::allocator<std::__1::pair<const char, char>>]" matches the argument listC/C++(289)
std::__1::vector<int> vect
no instance of constructor "std::__1::vector<_Tp, _Allocator>::vector [with _Tp=int, _Allocator=std::__1::allocator<int>]" matches the argument listC/C++(289)

使用 -std=c++11(或更高)。

您正在尝试使用 C++11 中引入的来自 std::initializer_list 的构造函数。 有关详细信息,请参阅 vectors and maps.

的文档