Thread: Vectors
View Single Post
Old Apr 17th, 2008, 2:55 PM   #7
White-Hat`
Programmer
 
Join Date: Sep 2005
Location: Oopland
Posts: 36
Rep Power: 0 White-Hat` is on a distinguished road
Re: Vectors

Okay, this is what I have now:

#include <iostream>
#include <string>
#include <vector>
#include <iterator>
#include <algorithm>
using namespace std;

int main() {
	string end = ("no");
	string inser;
	string lst;
	vector<string> names;
	do {
		cout << "Enter as many names as you'd like; Enter stop when you're finished." << endl;
		cin >> inser;
		names.push_back(inser);
		if(inser == ("stop")) {
                names.pop_back();
		cout << "Would you like to list the names?" << endl;
		cin >> lst;
		cout << "Would you like to end?" << endl;
		cin >> end;
		}
		if (lst == ("yes")) {
			copy(names.begin(), names.end(), ostream_iterator<string>(cout, "\n"));
		}
	}
		while (end != ("yes"));
}

The only thing I don't understand is where the iterator comes into play here.. If you could explain that for me it would be great. (edit: found a flaw in the stop loop, adding it as a name. included the pop_back command)
White-Hat` is offline   Reply With Quote