Im trying to use a variable vector array for a variable amount of classes. I cant seem to initialize any of the vectors variables. Is there a better way to make a variable sized array? This seems like a hassle.
#include <iostream>
#include <string>
#include <vector>
usingnamespace std;
int main () {
int clsnm;
int sum=0;
cout<<"How many classes do you have?";
cin>>clsnm;
vector<int> cls[clsnm];
int loop;
loop = clsnm;
while (loop > 0) {
loop = loop +1;
cin>>clsnm[loop];
sum = sum + clsnm;
}
}
#include <iostream>
#include <vector>
usingnamespace std;
int main () {
int clsnm;
cout<<"How many classes do you have?";
cin>>clsnm;
vector<int> cls(clsnm);
for (int i = 0; i < cls.size(); ++i)
{
cout << "Enter int value " << i << ": ";
cin >> cls[i];
}
for (int i = 0; i < cls.size(); ++i)
{
cout << "cls[" << i << "] = " << cls[i] << ' ';
}
}