Unhandled execption error!

I am writing a monogram program that allows user to enter full name (first, middle, and last name). The program will get all three initials of each name and put them together in a monogram.
It worked fine until I want to loop and do another monogram. I get this error after I enter 'y' when it asks me to do another monogram:

"Unhandled exception at at 0x76C0C54F in Problem Set Strings Monogram.exe: Microsoft C++ exception: std::out_of_range at memory location 0x003BFA4C."

I think it has something to do with the while loop, but it seems fine to me. I am just a beginner still so any help would be great. Thanks in advance!!
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
38
39
40
41
42
#include "stdafx.h"
#include <iostream>
#include "string"

using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
	
	string fullName;
	char firstInitial;
	char secondInitial;
	char thirdInitial;
	char doAgain;
	int positionOffirstSpace;
	int positionOfsecondSpace;

	do 
	{
		system ("CLS");
		cout << "Enter your full name (first middle last):  ";
		getline(cin,fullName);

		firstInitial = fullName[0];		//gets first initial

		positionOffirstSpace = fullName.find(" ");		//gets position of first space             
		secondInitial = fullName[positionOffirstSpace+1];		//gets intial of middle name by adding 1 to position of space
	
		fullName.erase(positionOffirstSpace,1);		//erases first space to allowing for second space to be found later
	
		positionOfsecondSpace = fullName.find(" ");		//gets position of second space
		thirdInitial = fullName[positionOfsecondSpace+1]; //gets intial of last name by adding 1 to position of space
	
		cout << firstInitial << thirdInitial << secondInitial << endl << endl;
		cout << "Would you like to do another???(y or n)   ";
		cin >> doAgain;

	}while (doAgain!='n');

	system ("pause");
	return 0;
}
Nevermind, i found the error. I needed this line of code at the bottom of the code:

cin.ignore(100,'\n');

The two inputs getline(cin,fullName) and cin must of mixed up or something. Can someone explain this to me?
Topic archived. No new replies allowed.