Help

I am writing a code that needs to ask a user for their name in the order of " Last, First I. " and returns it as " First I. Last " and I need help.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <string>
#include <vector>
#include <iostream>
#include <istream>
#include <ostream>
#include <iterator>
#include <sstream>
#include <algorithm>

using namespace std;

int main()
{

	int x = 0;
	string str;

	cout << "Enter name as Last, First I. " << endl;
	cin >> str;

	// construct a stream from the string
	stringstream strstr(str);

	// use stream iterators to copy the stream to the vector as whitespace separated strings
	istream_iterator<string> it(strstr);
	istream_iterator<string> end;
	vector<string> results(it, end);

	// send the vector to stdout.
	ostream_iterator<string> oit(cout);
	copy(results.begin(), results.end(), oit);

	cout << "Rearranged name: " << endl;

	cin >> x;

}


That is what I have so far but it just exits and I used an example I found online as a sort of template, I have the program running with no errors, which is a good start for me. However the program exits almost instantly after typing in my name, how can I make it display the output name rearranged in teh right order?
Last edited on
Topic archived. No new replies allowed.