#include <iostream>
#include <string>
using namespace std;
struct student {
string names;
int age;
};
int main()
{
student stu[3];
string name = "ABC";
for (int i=0; i < 3; i++) {
stu[i].names = "student_";
stu[i].names += name[i];
}
for (int i = 0; i < 3; i++) {
cout << "name:" << stu[i].names << endl;
}
system("pause");
return 0;
}
这样的处理关键在于第12行
一个字符串数组可以在循环中进行名字的命名,效果如下
name:student_A
name:student_B
name:student_C