How to initialize a vector with similar string N times in C++

1 Answer

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

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

int main() 
{
	std::vector<string> vec(4, "C++");

	for (string s : vec)
		cout << s << " ";
	
	cout << endl;

	return 0;
}

/*
run:

C++ C++ C++ C++

*/

 



answered Feb 15, 2018 by avibootz
...