How to initialize a list with an array in C++

1 Answer

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

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

int main() 
{
	string arr[] = { "c++", "c", "c#", "java", "python" };

	std::list<string> lst(arr, arr + sizeof(arr) / sizeof(string));

	for (string s : lst)
		cout << s << endl;

	return 0;
}

/*
run:

c++
c
c#
java
python

*/

 



answered Feb 16, 2018 by avibootz

Related questions

1 answer 159 views
1 answer 144 views
1 answer 151 views
151 views asked Feb 16, 2018 by avibootz
1 answer 174 views
1 answer 147 views
1 answer 190 views
...