How to use constant reference to a vector of 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;

void print(const vector<string> &vec)
{
	for (auto s : vec) {
		cout << s << endl;
	}
}

int main()
{
	vector<string> vec{ "c++", "java", "php" };

	print(vec);

	return 0;
}


/*
run:

c++
java
php

*/

 



answered May 26, 2018 by avibootz

Related questions

1 answer 339 views
1 answer 188 views
188 views asked Dec 19, 2024 by avibootz
2 answers 274 views
1 answer 199 views
199 views asked Feb 23, 2022 by avibootz
1 answer 320 views
1 answer 257 views
...