Answers for "c++ vector print"

C++
5

c++ vector print

for(int i = 0; i < vec.size(); i++)
    std::cout << vec[i] << ' ';
Posted by: Guest on January-22-2021
6

c++ print elements of vector to the console

#include <iostream>
#include <vector>

int main()
{
	std::vector<int> myVector = {1, 2, 3, 4, 5, 6};

	for(int i = 0; i < myVector.size(); i++)
	{
		std::cout << myVector[i] << std::endl;
        
        //***** alternate method *******
		//std::cout << myVector.at(i) << std::endl;		
	}	
}
Posted by: Guest on November-23-2019

Browse Popular Code Answers by Language