tags:

views:

124

answers:

3

Hi, I'm trying to use a vector of strings in my code instead of an array of strings but apparently I miss some detail in the declaration of the vector. Using the following code, I get this error: ‘vector’ was not declared in this scope

// Try to implement a vector of string elements

#include<iostream>

using namespace std;

int main() {
    const int MAX_ITEMS = 10;
    vector<string> my_vector(MAX_ITEMS);
    return 0;
}

How should I correctly declare the vector?

+7  A: 

You have to include the header:

#include <vector>
#include <string>
helium
+2  A: 

You need:

#include <vector>
Jim Buck
+8  A: 

You should add these includes:

#include <vector>
#include <string>
IVlad
So, all the while, I was using a strange version of strings? What are the differences between the std one and the one included in <string>?
Morlock
@Morlock: This is the standard string. Perhaps your `<iostream>` includes `<string>` for you (some implementations do, others don't) but there's no reason for it to include `<vector>`.
UncleBens
@UncleBens Thanks for the the details. I thought I came across something stating that there was a string type normally implemented, but that it was better to prefer the one from <string>. I think I saw this in the cplusplus.com C++ tutorial.
Morlock