Apr 21, 2013 at 6:26pm UTC
Your loops won't execute because students.size() is zero.
Apr 21, 2013 at 6:31pm UTC
thanks for point it out.
will to adjust the code.
Apr 21, 2013 at 6:42pm UTC
I have hard time understanding what this line does:
students.push_back(a);
What exactly is a
?
Shouldn't it be..
students.push_back(student);
or something like that?
Last edited on Apr 21, 2013 at 6:43pm UTC
Apr 21, 2013 at 7:56pm UTC
There is no declaration for "a", so the compiler should stop on error. Yes, pushing "student" sounds more proper.
Apr 21, 2013 at 8:33pm UTC
If you are trying to learn vectors check out this page
http://www.cplusplus.com/reference/vector/vector/
and something to play with would be this
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
vector<unsigned int > vec;
string size, error;
do {
error = "false" ;
cout << "How many numbers would you like to input into the vector?\nSize: " << flush;
getline(cin,size);
for (unsigned int i = 0; i<size.size(); i++) if (isalpha(size[i])) error = "true" ;
} while (error == "true" );
string nums[atoi(size.c_str())];
do {
error = "false" ;
for (unsigned int i = 0; i<(unsigned int )atoi(size.c_str()); i++){
cout << "Number " << i+1 << ": " << flush;
getline(cin,nums[i]);
}
for (unsigned int i = 0; i<(unsigned int )atoi(size.c_str()); i++) for (unsigned int j = 0; j<nums[i].size(); j++) if (isalpha(nums[i][j])) error = "true" ;
} while (error == "true" );
for (unsigned int i = 0; i<(unsigned int )atoi(size.c_str()); i++) vec.push_back((unsigned int )atoi(nums[i].c_str()));
for (unsigned int i = 0; i<(unsigned int )vec.size(); i++) cout << vec[i] << endl;
Last edited on Apr 21, 2013 at 8:34pm UTC