Run Time Error in Beginners pig latin HELP

When I try run my program it says "this application has requested the Runtime to terminate in an unusual way"

I am to make a simple Piglatin translation program, and I thought I wrote the code well (to my standards at least, I am very basic)

any help is so appreciated!!!

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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
  #include<iostream> 
#include<string>
#include<vector>
#include <fstream>
using namespace std;

//functions here
void fillVector (vector <string> & n); //fills the vector with fin
void pigLatin (string& x); //this function changes the string into piglatin 
void outputVector (vector<string> n); //this outputs the vector and all word count information 
int wordCount (vector <string> n); //this function counts all the words
int letterCount (vector <string> n); //this function counts all the letters 
int counter (string x); //this function aids the letter counter
int charCounter (vector <string> n); //this function counts all the characters
int charCounterhelp (string x); //this funtion helps the charcounter

//constant strings here
string vowel = "way"; 
string space = " "; 
string cons = "ay"; 

int main()
{
	vector <string> phrase(1000000); 
	fillVector (phrase); 
	outputVector (phrase); 
}
void fillVector (vector <string> & n)
{
		ifstream fin; 

		fin.open("data.txt"); 
		if(fin.fail())
		{
			cout << "data.txt failed to open" << endl; 
			exit (0); 
		}
		else
			cout << "data.txt has opened" << endl; //this is wthe place where everything stops running 

		string word; 
	
		do
		{
			getline(fin, word); //reads it into the vector
			pigLatin (word); //send word to the pigLatin function 
			n.push_back(space); 
			n.push_back(word); //add the new word to the vector 
		}
		while(!fin.eof());

		cout << "the vector has been filled" << endl; 
}
void pigLatin (string& x)
{
	string temp, notVowel; 

	for (int i = 0; i < x.size(); i++)
	{
		if (x.at(i) == 'a' || x.at(i)== 'e' ||x.at(i)== 'i' || x.at(i)== 'o' || x.at(i)== 'u' ) //tests the first value 
		{	x += vowel; 
			break; 
		}
		else //if is a constant
		{
			do
			{
				temp += x.at(i); //temp is equal to all the consts
				//find a way to erase all before temp here 
				x.erase(x.at(i), temp.length()); 
			}
			while (!(x.at(i) == 'a' || x.at(i)== 'e' ||x.at(i)== 'i' || x.at(i)== 'o' || x.at(i)== 'u')); 
			
			if ((x.at(i) == 'a' || x.at(i)== 'e' ||x.at(i)== 'i' || x.at(i)== 'o' || x.at(i)== 'u'))
				notVowel += x.at(i); 
			x += (notVowel + cons); 
			break; 
		} //end of else bracket 
	} //end of the for loop bracket 

} //end of piglatin bracket 
void outputVector (vector<string> n)
{
	for (int i = 0; i < n.size(); i++)
		cout << n.at(i); //runs through and outputs 
	cout << "There are " << wordCount (n) << " in the phrase" << endl; 
	cout << "There are " << letterCount (n) << " in the phrase" << endl; 
	cout << "There are " << charCounter (n) << " in the phrase" << endl; 

}
int wordCount (vector <string> n)
{
	int wordCount = 0; 
	for (int i = 0; i < n.size(); i++)
		if(n.at(i) != space)
			wordCount ++; 
	return wordCount; 
}

int letterCount (vector <string> n) 
{
	int letterCount = 0; 
	for (int i = 0; i < n.size(); i++)
		letterCount = counter (n.at(i)); 
	return letterCount; 
}
int counter (string x)
{
	int temp = 0; 
	for (int i = 0; i < x.size(); i++)
	{	
		temp ++; 
	}
	return temp; 
}
int charCounter (vector <string> n)
{
	int charCount = 0, letters = 0; 
	
	letters = letterCount (n); 

	for (int i = 0; i < n.size (); i++)
		charCount = charCounterhelp (n.at(i)); 
	
	return (charCount + letters); 
}
int charCounterhelp (string x)
{
	int temp = 0; 

	for (int i = 0; i < x.size(); i++)
	{
		char t = x.at(i); 
		if (isspace (t) == false) //if it is not a space
			 temp += i;  
	}
	
	return temp; 
}
Is there a reason you start out with 1000000 empty strings in your vector?
Topic archived. No new replies allowed.