vector initialization

I have a little program and a big problem with it. I can't find out how to solve it. The program doesn't compile.
Here is a code

1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main()
{
    string mystr[]={"Tom", "John", "Ron};
    vector<string> v=(mystr, mystr+sizeof(mystr)/sizeof(string);

    return 0;
} 
First you have a couple of errors in your code. You missed a terminating quote for the last string, and your parentheses don't match.

For the actual problem you don't want to use the assignment operator. You want to use the constructor.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main()
{
    string mystr[]={"Tom", "John", "Ron"};

    vector<string> v(mystr, mystr+sizeof(mystr)/sizeof(string));

    return 0;
}


Thanks man, I understood. It works.
Topic archived. No new replies allowed.