【问题标题】:error: type 'std::__1::basic_string<char>' does not provide a call operator [closed]错误:类型 'std::__1::basic_string<char>' 不提供调用运算符 [关闭]
【发布时间】:2018-06-21 19:08:08
【问题描述】:

我有一个由字符串和整数组成的对向量,例如:{("ABC", 15), ("DEFG", 29)}。我想将字符串拆分为向量中的单独字符,例如 {'A', 'B', 'C'}。我的代码是:

for (std::pair<std::string, int> i: code) 
  {
    std::vector <char> letters;
    for (char b: i.first()) 

'代码'是原始向量。这段代码给了我错误:

error: type 'std::__1::basic_string<char>' does not provide a call operator
    for (char b: i.first()) 
                 ^~~~~~~

我不明白这个,有没有办法解决这个问题?

【问题讨论】:

  • 错字:istd::pair。写i.first 而不是i.first()
  • for (char b: i.first()) 更改为for (char b: i.first)

标签: c++ vector c++14 std-pair


【解决方案1】:

std::pairfirst 是成员变量,而不是方法。去掉first后面的括号。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-03-27
    • 1970-01-01
    • 2020-12-12
    • 1970-01-01
    • 1970-01-01
    • 2022-07-04
    • 1970-01-01
    • 2021-04-07
    相关资源
    最近更新 更多