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

@grumpy

Taking that into consideration, I rewrote it to be more hassle-free for the user.

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

int main() {
	string end = ("no");
	string inser;
	string x;
	vector<string> names;
	cout << "Enter as many names as you'd like; Enter stop when you're finished." << endl;
	do {
		cin >> inser;
		names.push_back(inser);
		if(inser == ("stop")) {
		names.pop_back();
		cout << "If you would like to list the names you have written, enter \"list\". Otherwise,  enter \"quit\" to end. To enter more names, enter \"more\"." << endl;
		cin >> x;
		}
		if (x == ("list")) {
			copy(names.begin(), names.end(), ostream_iterator<string>(cout, "\n"));
		}
			else if (x == ("more")) {
				cout << "Okay, we'll enter more!";
				cout << endl;
			}
			else {
				if (x == ("quit")) {
					end = ("quit");
				}
			}
	}
		while (end != ("quit"));
		return 0;
}
White-Hat` is offline   Reply With Quote