For Loop of a copy vector

Did I copy my vector the right way? I don't know why this for loop won't run?


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
  // Example program
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main()
{
 vector<string> line;
 line.push_back("Hello");
 line.push_back("My");
 line.push_back("Name");
 line.push_back("Is");
 line.push_back("John");
 
vector<string> display_line(line.begin(),line.end());


for(unsigned i=0; i<display_line.size(); ++i) display_line[i];
 
 
}
Last edited on
What do you expect to happen? The program seems to be working as expected when I run the program. However I do wonder what you expect to happen in that for loop. Perhaps you meant to actually print the elements of that vector?

@jib Your correct. I wanted to display every index of the copy vector.
Last edited on
So then why don't you try printing the element? Just because your vector is named display_line doesn't mean it'll magically print it's elements to the screen.

@jib Thanx man! I found my error! I forgot cout
Last edited on
Topic archived. No new replies allowed.