I tried to do it using the vector<string> and iterating through it to create the object but while assigning them value i am getting error
#include <bits/stdc++.h>
using namespace std;
class Student {
public: string name;
int rollno;
void display() {
cout << "Name of student is " << name <<"nHis Roll Number is " << rollno <<"n";
}
};
int main() {
std::vector < string > obj_name;
for (int i = 0; i < 10; i++) {
string temp;
cin >> temp;
obj_name.push_back(temp);
}
for (int i = 0; i < 10; i++) {
Student obj_name[i];
}
for (int i = 0; i < 10; i++) {
int x;
cin >> x;
obj_name[i].rollno = x;
}
return 0;
}
New contributor
Shiv Patil is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.