So all i have to do is clean it up but cant find the source to the actual error. Heres my code:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
bool isVowel(char ch);
string rotate(string pStr);
string pigLatinString(string pStr);
int main()
{
ifstream infile;
string newstr;
int length;
char achar;
string str;
string str1;
string str2;
string str3;
string pStr;
char ch;
infile.open("C:\\201\\PigLatin.txt");
if(infile.is_open() == false)
{
std::cerr << "Error, unable to open file." << std::endl;
return 1;
}
std::string word;
while(infile.fail() == false)
{
infile >> word;
std::cout << pigLatinString(word) << ' ';
}
cout << endl;
cout << "Pig Latin String Is: " << endl;
cout << endl;
while (!infile.eof())
{
infile.get(achar);
if (achar != ' ')
{
str = str + achar;
}
else
{
cout << pigLatinString(str)<< " ";
str = "";
}
}
if (achar == '!')
{
length = static_cast<unsigned int>(str.length());
newstr = str.substr(0,(length-2));
cout << " " << pigLatinString(newstr) << "!";
}
if (achar == '?')
{
length = static_cast<unsigned int>(str.length());
newstr = str.substr(0,(length-2));
cout << " " << pigLatinString(newstr) << "?";
}
if (achar == '.')
{
length = static_cast<unsigned int>(str.length());
newstr = str.substr(0,(length-2));
cout << " " << pigLatinString(newstr) << ".";
}
cout << endl;
str = "";
cout << endl;
isVowel(ch);
rotate (pStr);
pigLatinString(pStr);
infile.close();
return 0;
}
bool isVowel(char ch){
switch (ch)
{
case 'A': case 'E':
case 'I': case 'O':
case 'U': case 'Y':
case 'a': case 'e':
case 'i': case 'o':
case 'u': case 'y': return true;
default: return false;
}
}
string rotate(string pStr)
{
string::size_type len = pStr.length();
string rStr;
rStr = pStr.substr(1, len - 1) + pStr[0];
return rStr;
}
string pigLatinString(string pStr)
{
string::size_type len;
bool foundVowel;
string::size_type counter;
if (isVowel(pStr[0]))
pStr = pStr + "-way";
else
{
pStr = pStr + '-';
pStr = rotate(pStr);
len = pStr.length();
foundVowel = false;
for (counter = 1; counter < len - 1; counter++)
if (isVowel(pStr[0]))
{
foundVowel = true;
break;
}
else
pStr = rotate(pStr);
if (!foundVowel)
pStr = pStr.substr(1,len) + "-way";
else
pStr = pStr + "ay";
}
return pStr;
}
here is what is in the file that it reads from:
hello there my friend.
Here is how it prints out into the command prompt:
ello-hay ere-thay y-may iend.-fray iend.-fray
Pig Latin String Is:
And finally here is the error that i receive(Click the link to see the error):