Erasing From Vector
Erasing From Vector
#include <iostream>
#include <vector>
using namespace std;
int main ()
{
unsigned int i;
vector<unsigned int> myvector;
return 0;
}
Output:
myvector contains: 4 5 7 8 9 10
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
using namespace std;
do
{
string name;
cout << "Enter student name (Enter to finish): ";
getline (cin, name);
vector<string>::iterator s;
vector<double>::iterator m;
for (s = student_names.begin(), m = student_marks.begin();
s != student_names.end();
++s, ++m)
{
do
{
cout << "Enter marks (0 to 100) for " << *s << ": ";
cin >> *m;
return 0;
}
#include <vector>
#include <iostream>
using namespace std;
//====================================================== main
int main() {
vector<float> a; // Declare a vector.
float temp;
while (cin >> temp) {
a.push_back(temp);
}
return 0;
}
//======================================================= sum
// sum adds the values of the vector it is passed.
float sum(const vector<float>& x) {
float total = 0.0; // the sum is accumulated here
for (int i=0; i<x.size(); i++) {
total = total + x[i];
}
return total;
}