Vectors in C++

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • makita18v
    New Member
    • Oct 2008
    • 7

    Vectors in C++

    So I have this program where I'm supposed to change all arrays into vectors. The program takes test values and assigns grades for them. The only problem is i've tried to change them into vectors, but I'm coming up with all sorts of errors, so here is some code with the array and the vector part is what I've tried to do.

    Code:
    char grades[] = {'A', 'B', 'C', 'D', 'E'};
    	vector<char> grades; //['A', 'B', 'C', 'D', 'E'];
    int scores[5]={0};
    	vector<int> scores;
    scores[index++] = aScore; // I don't have a clue how to change this to a vector
  • Ganon11
    Recognized Expert Specialist
    • Oct 2006
    • 3651

    #2
    Check out the vector's .push_back method...combin ed with a simple for...loop, it should do what you want.

    Comment

    • Studlyami
      Recognized Expert Contributor
      • Sep 2007
      • 464

      #3
      Your vectors have the same variable name as your arrays. You can't have 2 variables of the same name. The push back function which Ganon stated will allow you to add a value into your vector.

      Comment

      Working...