如何在c+中创建、访问和利用字符串数组+; 我是C++的新手,我想知道如何创建空数组字符串数组, 到目前为止,我有: #include <iostream> #include <iomanip> using namespace std; int main() { int numOfStudent; char again; do { cout << "How many students are in the class?"; cin >> numOfStudent; while (numOfStudent > 30 || numOfStudent < 5) { cout << "The number of students must be in the range 5 - 30\n"; cout << "How many students are in the class?"; cin >> numOfStudent; } for (int count = 1; count <= numOfStudent; count++) cout << "Enter the full name of student " << count << endl; cin >> // this is the part where i want to use an array to store cout << "Here is the list of students you have entered:\n"; for (int x = 1; x <= numOfStudent; x++) cout << x << ". " // and this is the part where i want to read an array and print out cout << "\nDo you want to continue (y/n)?"; cin >> again; } while (again == 'Y' || again == 'y'); } #包括 #包括 使用名称空间std; int main() { 国际学生; 再次烧焦; 做 { cout>numof学生; 而(numOfStudent>30 | | numOfStudentnumof学生; 而(numOfStudent>30 | | numOfStudentnumof学生; 而(numOfStudent>30 | | numOfStudent
来说,这似乎是一个家庭作业问题,但即使是这样,它也是如此基本,代码答案应该有助于让您跳转到更复杂的主题:如何在c+中创建、访问和利用字符串数组+; 我是C++的新手,我想知道如何创建空数组字符串数组, 到目前为止,我有: #include <iostream> #include <iomanip> using namespace std; int main() { int numOfStudent; char again; do { cout << "How many students are in the class?"; cin >> numOfStudent; while (numOfStudent > 30 || numOfStudent < 5) { cout << "The number of students must be in the range 5 - 30\n"; cout << "How many students are in the class?"; cin >> numOfStudent; } for (int count = 1; count <= numOfStudent; count++) cout << "Enter the full name of student " << count << endl; cin >> // this is the part where i want to use an array to store cout << "Here is the list of students you have entered:\n"; for (int x = 1; x <= numOfStudent; x++) cout << x << ". " // and this is the part where i want to read an array and print out cout << "\nDo you want to continue (y/n)?"; cin >> again; } while (again == 'Y' || again == 'y'); } #包括 #包括 使用名称空间std; int main() { 国际学生; 再次烧焦; 做 { cout>numof学生; 而(numOfStudent>30 | | numOfStudentnumof学生; 而(numOfStudent>30 | | numOfStudentnumof学生; 而(numOfStudent>30 | | numOfStudent,c++,arrays,C++,Arrays,来说,这似乎是一个家庭作业问题,但即使是这样,它也是如此基本,代码答案应该有助于让您跳转到更复杂的主题: #include <iostream> #include <iomanip> #include <vector> #include <string> using namespace std; int main() { int numOfStudent; char again; vector<string>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
using namespace std;
int main()
{
int numOfStudent;
char again;
vector<string> students;
do
{
cout << "How many students are in the class?";
cin >> numOfStudent;
while (numOfStudent > 30 || numOfStudent < 5)
{
cout << "The number of students must be in the range 5 - 30\n";
cout << "How many students are in the class?";
cin >> numOfStudent;
}
for (int count = 1; count <= numOfStudent; count++)
{
string name;
cout << "Enter the full name of student " << count << endl;
cin >> name; // this is the part where i want to use an array to store
students.push_back(name);
}
cout << "Here is the list of students you have entered:\n";
for (int x = 1; x <= numOfStudent; x++)
cout << "Student #"<<x << " is "<<students.at(x-1)<<"."<<endl; // and this is the part where i want to read an array and print out
cout << "\nDo you want to continue (y/n)?";
cin >> again;
} while (again == 'Y' || again == 'y');
}
#包括
#包括
#包括
#包括
使用名称空间std;
int main()
{
国际学生;
再次烧焦;
矢量学生;
做
{
cout>numof学生;
而(numOfStudent>30 | | numOfStudent<5)
{
库特是一名学生;
}
对于(int count=1;countstd::vector
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
using namespace std;
int main()
{
int numOfStudent;
char again;
vector<string> students;
do
{
cout << "How many students are in the class?";
cin >> numOfStudent;
while (numOfStudent > 30 || numOfStudent < 5)
{
cout << "The number of students must be in the range 5 - 30\n";
cout << "How many students are in the class?";
cin >> numOfStudent;
}
for (int count = 1; count <= numOfStudent; count++)
{
string name;
cout << "Enter the full name of student " << count << endl;
cin >> name; // this is the part where i want to use an array to store
students.push_back(name);
}
cout << "Here is the list of students you have entered:\n";
for (int x = 1; x <= numOfStudent; x++)
cout << "Student #"<<x << " is "<<students.at(x-1)<<"."<<endl; // and this is the part where i want to read an array and print out
cout << "\nDo you want to continue (y/n)?";
cin >> again;
} while (again == 'Y' || again == 'y');
}