c++ vector print

#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;		
	}	
}

4.5
10
Krish 100200 points

                                    for(int i = 0; i &lt; vec.size(); i++)
    std::cout &lt;&lt; vec[i] &lt;&lt; ' ';

4.5 (10 Votes)
0
3.8
5
Awgiedawgie 440220 points

                                    // A recursive function able to print a vector
// of an arbitrary amount of dimensions.
template&lt;typename T&gt;
static void show(T vec)
{
  std::cout &lt;&lt; vec;
}


template&lt;typename T&gt;
static void show(std::vector&lt;T&gt; vec)
{
  int size = vec.size();
  if (size &lt;= 0) {
    std::cout &lt;&lt; &quot;invalid vector&quot;;
    return;
  }
  std::cout &lt;&lt; '{';
  for (int l = 0; l &lt; size - 1; l++) {
    show(vec[l]);
    std::cout &lt;&lt; ',';
  }
  show(vec[size - 1]);
  std::cout &lt;&lt; '}';
}

3.8 (5 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
c++ print vector function print all items in vector c++ how to print a vector array printing elements of vector c++ how to print elements in vector how to print vector of vector in c++ show in console vector c++ how to print elements of a vector in c++ how to print a vector of string how to print vector&lt;&lt;vector&gt;int&gt; how to print elements in a vector in c++ print a vector of strings c++ print all elements in vector c++ how to print vector c++ print vector c++ function print 3d vector c++ print vector in c++ using STL print vectors c++ vector printing c++ print c++ vector printing elements of a 3d vector print vector in c++ stl how to print out values of vector c++ print vector in c++11 print elements of a vector c++ print a 3d vector in c++ how to print vector to console c++ vector print cpp print vector 3 c++ how to print a vect c++ return vector and print it points vector get content print vector values get everything in vector c++ c++ print all elements in vector string vector print c++ print vecto print all string in vector print dump c++ algorytm orint value of vector c++ how to print all values in vector print vector content c++ print a character vector display the content of the vector c++ print std vector vector print all c++ cpp stl print a vector c++ cout vector of strings how to print out the contents of a stringc++ how to print out the contents of a vector c++ vector cout c++ prints vector values in cpp vector in c++ output how to output aeverything in a vecot c++ print vector en c++ enter all numbers from input to vector c++ c++ print all vector elements cout vector char iterator how to print the out put for vector inside vector print elements of vector how to print any element of vector in c++ printing a whiole stl vector fastest way to print ints of a vector how to print element of vector c++ function to print vector c++ c++ print all items in vector print all elements in a vector c++ how to print element in vector c++ c how to print a whole vector c++ print all vector values how to give a vector in std output how to print a vector easily in c++ print vectors how to print vector array c++ printing elements from a avector c++ print vectors how to print a whole vector in c print vector without space print full vector c++ printing from string vector c++ print a vector print values from vector c++ c++ vector string print out how to print values of vector in c++ print a vector using auto how to print out the vector in c++ how to print an vector in cpp printing an element in a vector c++ print elements in vector how to display the contents of a vector in c++ calling on a vectorwith string print int vector c++ print int vector c++# print contents of vector c++ display single vector contents c++ display vector contents c++ why we use auto in vector printing select print vector c++ c++ print vecotr output vector to screen c++ print vector of char how to print a string vector in c++ print a vector string print string vector c++ print entire vector c++ c++ vector peint c++ stream vector how to print string vectors 2nd elements in c++ std::cout a vector in c++ how to print a vector printing a vector print values of vector c++ how to cout contents in vector C++ how to cout contents in vector how to print a vertex c++ find and print a vector how to find and cout a vectorc++ how to find and cout a vector C++ c++ print out vector nicely print vector function c++ how to print out with a function vector cpp vector cout how to output the vector c++ print vector&lt;char&gt; cout a fector copy algorithm c++ used to print vector how to printa vector in c++ c++ print contents of a vector cout element from vector print std::vector c++ vector print all eleements of vector print out values of vector&lt;int&gt; how to print out the contents of a vector print all vector c++ cout a vecotr c++ vector cout function to write out a vector of doubles to a given output stream how to print elements in a vector c++ print values in vector how to display vector string in c++ print vector print on screen c++ vectors how to print the whole vector cout a vector cpp how to cout vector c++ cout vector in c++ how to print a vector in stl how to print out a vector c++ how to print every element in a vector c++ cout a vector c++ printing the vector in c++ how to print contents of vector inside a vector c++ how to output vector c++ how to cout vector of vector how to display a vector in c++ for loop to print vector c++ output a vector c++ how to see whats in a vector c++ display vector c++ cout vector print the contents of a vector c++ from the top print the contents of a vector c++ from top cout a vector print char vector c++ how to display values in vector c++ print a vector how to print values in a vector c++ how to print all values of a vector print vector c++ in a line print all values in a vector c++ how to cout a vector how to print a comment in between elements in c++ vector cout syntax c++ print entire vector print vector cpp how to print whole vector in c++ c++ cout whole vector print vector as string c++ c++ print elements of vector print vector to console c++ print an vector c++ c++ print vector as string cout elements of vector c++ C++ print each string in vector how to print out a vector of numbers from object print all items of a vector c++ print vector in cpp c++ how to cout vector print vecotr in c++; printing vector c++ using auto printing vector c++ view output in C++ vectors how to print elements of vector in c++ printing a vector c++ vector print c++ output vector to ostream c++ how to cout vector in c++ c++ how to print a vector cant print c++ vector prints indices print vector c++ gives 0 1 2 how to print vector elements in c++ output vector c++ c++ macro print vector print a vector in cpp how to print a vector c++ cpp print vector vector print in c++ vector c++ cout print out vector c++ how to print a vector with spaces in c++ how to output a vector c++ cpp printing vector values with a space how to print the vector in c++ printing a vector in c++ c++ cout vector c++ how to print contents of vector c++ how to print vector c++ how to print std::vector how to print a vector in cpp cout vector c++ print vector array with spaces c++ cpp cout vector for x in vector c++ c++ vector print read element inside vector c++17 printing contents of vector c++ c++ printing vectors print elements of vector c++ c++ vector print elements cout vector elements c++ how to print vector print vector in c++ how to print a vector in c++ print a vector in c++ how to print vector in c++ c++ print vector of strings print vector elements in c++ print vector c++ print all elements of vector c++ how to cout a vector in c++ c++ print vector inserting elements in vector c++ how to print out vector c++ print vector contents c++ cout vector string print out a vector c++ vector values are not printing c++ how to print out every string in a vector print a vector c++ how to print out a vector in c++ cout vector char c++ c++ print elements of vector to the console
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source