I'm flicking through a set of C++ tutorials and am playing with the header includes for one of the examples. Why does the following still run, even with algorithm
and vector
commented out?
//#include <algorithm>
#include <iostream>
#include <random>
//#include <vector>
using namespace std;
int main() {
vector<int>::const_iterator iter;
cout << "Creating a list of scores.";
vector<int> scores;
scores.emplace_back(1500);
scores.emplace_back(3500);
scores.emplace_back(7500);
cout << "\nHigh Scores:\n";
for (iter = scores.begin(); iter!=scores.end(); iter++) {
cout << *iter << endl;
}
cout << "\nFinding a score.";
int score;
cout << "\nEnter a score to find: ";
cin >> score;
iter = find(scores.begin(), scores.end(), score);
if (iter!=scores.end()) {
cout << "Score found.\n";
} else {
cout << "Score not found.\n";
}
cout << "\nRandomising scores.";
random_device rd;
default_random_engine generator(rd());
shuffle(scores.begin(), scores.end(), generator);
cout << "\nHigh Scores:\n";
for (iter = scores.begin(); iter!=scores.end(); iter++) {
cout << *iter << endl;
}
cout << "\nSorting scores.";
sort(scores.begin(), scores.end());
cout << "\nHigh Scores:\n";
for (iter = scores.begin(); iter!=scores.end(); iter++) {
cout << *iter << endl;
}
return 0;
}