Nat*_*ale 6 c++ xcode header vector 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;
}
Run Code Online (Sandbox Code Playgroud)
没有意识到这#include <vector>是必需的。我认为它是标准库模板的一部分;我在 VSCODE IDE 中运行了这段代码,它对我来说效果很好
#include <iostream>
#include <vector>
using namespace std;
int main()
{
uint_least8_t i; // trying to be conscious of the size of the int
vector<int> vect;
for(i = 0; i < 5; ++i)
{
vect.push_back(i);
}
for(auto i : vect)
{
cout << i << endl;
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
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;
}
Run Code Online (Sandbox Code Playgroud)
解决了我的问题。
使用命名空间 std 将向量和字符串放置在命名空间 std 中;
| 归档时间: |
|
| 查看次数: |
5315 次 |
| 最近记录: |