18

I ran this code on a different IDE and it was successful. For some reason I get the above error message on Xcode. I assume I'm missing a header of some kind, but I'm not sure which one.

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

int main() {
    vector<string> listRestaurants;  // error: Implicit instantiation of undefined template
    return 0;
}
m7913d
  • 10,244
  • 7
  • 28
  • 56
Nathan Hale
  • 191
  • 1
  • 1
  • 3

5 Answers5

21

Xcode 10.2.1 was showing me the error 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;
}

Fixed my issue.

Sauvik Dolui
  • 5,520
  • 3
  • 34
  • 44
10

If adding std:: is not the issue for you, then check if you have #include <vector>. That fixed the issue for me.

Parneet Kaur
  • 101
  • 1
  • 3
6

Didn't realize that #include <vector> is required. I thought it was part of standard library template; I ran this code in VSCODE IDE and it worked fine for me

#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;
}
Stats_Lover
  • 396
  • 4
  • 11
2

From the comments:

The std namespace houses both of those templates. Change vector to std::vector, and string to std::string. – WhozCraig

Quentin
  • 62,093
  • 7
  • 131
  • 191
0

the vector and string were placed in the namespace std using namespace std;

RyanLi
  • 63
  • 8
  • 3
    [**Never** use `using namespace std;`](https://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice). – Quentin Mar 13 '18 at 09:32
  • He didn't say to use using. You always can use like std::vector or std::string. By the way @RyanLi was right. – Daniil T. Aug 07 '19 at 20:20