mercredi 27 mai 2015

Trouble dispaying names with Vector coding

Good afternoon.....I am currently a student in a C++ course and we are writing code for Vectors. In an assignment we have to display 3 student names. When I add the names after the following code is run it only displays the number of vectors and not the names (as is required). Any assistance is appreciated.

#include "stdafx.h"
#include <iostream>
#include <string>
#include <vector>



using std::cout;
using std::cin;
using namespace std;

int main()

{
bool running = true;
char choice;
vector <string> studentVector;
cout << "My Student Vector" << endl;
while (running == true){
cout << "Choose a Selection: [A]dd Student, [V]iew Student, [R]emove      Student, [E]xit" << endl;
cin >> choice;
cin.ignore();

if (choice == 'A' || choice == 'a')
{
cout << "Enter Student's Name: ";
string tempVar;
getline(cin, tempVar);

studentVector.push_back(tempVar);
}
else if (choice == 'V' || choice == 'v')
{
cout << "You have " << studentVector.size() << "Student(s)." << endl;
for (int i = 0; i << studentVector.size(); i++)
cout << i << ". " << studentVector.at(i) << endl;
}
else if (choice == 'R' || choice == 'r')
{

int pos;
cout << "Enter the vector position for the student in question: ";
cin >> pos;
cin.ignore();

studentVector.erase(studentVector.begin() + pos);
}
else if (choice == 'E' || choice == 'e')
running = false;

else
cout << "Invalid Selection" << endl;
}

Aucun commentaire:

Enregistrer un commentaire