使用矢量编码显示名称时遇到问题 下午好……我现在是一个C++课程的学生,我们正在编写向量的代码。在作业中,我们必须显示3个学生姓名。当我在运行以下代码后添加名称时,它只显示向量的数量,而不显示名称(根据需要)。感谢您的帮助 #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; } } #包括“stdafx.h” #包括 #包括 #包括 使用std::cout; 使用std::cin; 使用名称空间std; int main() { bool running=true; 字符选择; 向量学生向量; cout

使用矢量编码显示名称时遇到问题 下午好……我现在是一个C++课程的学生,我们正在编写向量的代码。在作业中,我们必须显示3个学生姓名。当我在运行以下代码后添加名称时,它只显示向量的数量,而不显示名称(根据需要)。感谢您的帮助 #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; } } #包括“stdafx.h” #包括 #包括 #包括 使用std::cout; 使用std::cin; 使用名称空间std; int main() { bool running=true; 字符选择; 向量学生向量; cout,c++,c++11,vector,C++,C++11,Vector,在for循环中显示名称,你真的是指i步骤1:正确缩进代码。在点击提交之前,使用实时预览验证代码是否可读。这确实是个问题。简单的输入错误。我想这就是我被卡住的地方。我们观看的视频将其作为循环语句,在视频…不确定它“应该”是什么。任何其他帮助都会很好。看起来你正在尝试比较这些值,但你没有。看一看。它应该是(int i=0;i

for
循环中显示名称,你真的是指
i步骤1:正确缩进代码。在点击提交之前,使用实时预览验证代码是否可读。这确实是个问题。简单的输入错误。我想这就是我被卡住的地方。我们观看的视频将其作为循环语句,在视频…不确定它“应该”是什么。任何其他帮助都会很好。看起来你正在尝试比较这些值,但你没有。看一看。它应该是(int i=0;i
。如果视频有