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 228 views
1 answer 98 views
98 views asked Dec 19, 2024 by avibootz
2 answers 158 views
1 answer 114 views
114 views asked Feb 23, 2022 by avibootz
1 answer 227 views
1 answer 169 views
...