List three ways to define a vector and give it ten elements,
each with the value 42. Indicate whether there is a preferred way to do so
and why.
But it does not say if it has to be a int or string ...
so i went for int and i got this
1 2 3 4 5 6 7 8 9 10 11 12 13
#include <iostream>
#include <vector>
using std::cout; using std::cin; using std::endl;
using std::vector; using std::string;
int main()
{
vector<int> (10, 42); // first
vector<int> {42, 42, 42, 42, 42, 42, 42, 42, 42, 42}; // second
return 0;
}
And i donno a third way to do it with an int
but i can do it with a string:
1 2 3 4 5 6 7 8 9 10 11 12 13
#include <iostream>
#include <vector>
using std::cout; using std::cin; using std::endl;
using std::vector; using std::string;
int main()
{
vector<string> (10, "42"); // first
vector<string> {10, "42"}; // second
vector<string> {"42", "42", "42", "42", "42", "42", "42", "42", "42", "42"}; // third
return 0;
}
So is there a third way with the int vector or no?