Sorting is pretty significant as an activity. C++11 provides improved reliability over C++98/03...
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
vector<int> myVector
int main()
{
// using std::find with vector and iterator:
int myInts[] = { 10, 20, 30, 40 };
vector<int> myVector (myInts,myInts+4); // vector of above ints
vector<int>::iterator it; // vector iterator
it = find (myVector.begin(), myVector.end(), 30);
if (it != myVector.end())
cout << "Element found in myVector: " << *it << '\n';
else
cout << "Element not found in myVector\n";
}
#include <iostream>
#include <map>
#include <algorithm> // find(), end()
#include <string>
using namespace std;
map<string, long> directory
int main()
{
map<string, long> directory; // declare a map container
directory["Alice"] = 9234567; // add key,value pairs
directory["Bob"] = 9876543;
directory["Carol"] = 8459876; // And so on ...
// Read some names and look up their numbers:
string name;
while(cin >> name)
if (directory.find(name) != directory.end())
cout << "The phone number for " << name << " is " << directory[name];
else
cout << "Sorry, no listing for " << name;
cout << endl;
}