Xcode C ++ Vectors:未定义模板的隐式实例化

时间:2018-03-12 23:49:35

标签: c++ xcode vector header implicit

我在不同的IDE上运行此代码并且成功了。出于某种原因,我在Xcode上收到上述错误消息。我想我错过了某种类型的标题,但我不确定是哪一个。

#include <iostream>
#include <limits>
#include <string>
#include <vector>

int main() {
    vector<string> listRestaurants;  //here is where the semantic error appears
    return 0;
}

5 个答案:

答案 0 :(得分:2)

Xcode 10.2.1向我显示了错误 Implicit instantiation of undefined template 'std::__1::vector<std::__1::basic_string<char>, std::__1::allocator<std::__1::basic_string<char> > >'

#include <iostream>
#include <vector>
int main(int argc, const char * argv[]) {
  std::vector<std::string> listRestaurants;

  ....
  return 0;
}

解决了我的问题。

答案 1 :(得分:2)

如果添加std ::不是您的问题,请检查您是否拥有#include <vector>。这为我解决了这个问题。

答案 2 :(得分:2)

没有意识到需要 UserPosition.aggregate([ { $match: { name: { $ne: "cash" } } }, { $group: { _id: "$name", long: { $sum: { "$cond": [{ "$gt": ["$units", 0] }, "$equity", 0] } }, short: { $sum: { "$cond": [{ "$lt": ["$units", 0] }, "$equity", 0] } }, net: { $sum: "$equity" }, } } ]).then((docs) => { NamePosition.update(docs) // this doesn't work }); 。我认为它是标准库模板的一部分;我在 VSCODE IDE 中运行了这段代码,对我来说效果很好

#include <vector>

答案 3 :(得分:-1)

向量和字符串放在命名空间std中 使用namespace std;

答案 4 :(得分:-1)

来自评论:

  

std命名空间包含这两个模板。将vector更改为std::vector,将string更改为std::string。 - WhozCraig