How to initialize vector with strings in C++

1 Answer

0 votes
#include <iostream>
#include <vector>
#include <string>

using std::cout;
using std::endl;
using std::vector;
using std::string;

int main()
{
	const char *arr[] = { "c", "c++", "java" };

	vector<string> vec(arr, arr + 3); 

	for (int i = 0; i < vec.size(); i++)
		cout << vec[i] << " ";
	
	cout << endl;

	return 0;
}


/*
run:

c c++ java

*/

 



answered May 19, 2018 by avibootz
...