I have a file that contains a bunch of sentences in it in English, and I need to be able to ifstream all of that and take every word and cout to the console everything converted in piglatin. Can somebody lead me in the right direction?
#include <iostream>
#include <fstream>
#include <iostream>
#include <string>
// Everything we will be using during the program
using std::ifstream;
using std::cout;
using std::cerr;
using std::string;
using std::cin;
int main()
{
// Process of opening the text document
ifstream infile;
infile.open("ASSGN8-A.txt");
// Checking to see if the file is open or not.
if (!infile)
{
cerr << "ERROR. FILE NOT OPEN"; // Error report
}
string text;
while (infile >> text)
{
}
return 0;
}
string toPigLatin()
{
}
Ok, so you are currently reading each word in your text file. So now you need to make it so you can pass a string to your toPigLatin function, figure out how you're going to convert it to pig latin and add a return statement, call the function form in your loop, and add an output to print to the screen. Check here: http://www.cplusplus.com/reference/string/string/ for the functions you'll probably use to change the word to pig latin.
Also, your missing your infile.close() statement and theirs no need to run the rest of the program if the file fails to open so you would have an else statement after you if with the rest of the program logic and the close statement.
//function prototype
string toPigLatin(string);
int main()
{
// Process of opening the text document
ifstream infile;
infile.open("ASSGN8-A.txt");
// Checking to see if the file is open or not.
if (!infile)
{
cerr << "ERROR. FILE NOT OPEN"; // Error report
}
//no need to run program logic if file fails to open
else {
string text;
string pigLatin;
while (infile >> text)
{
//append returned string to piglatin string
}
//output result
cout << pigLatin << endl;
//close file
infile.close();
}
return 0;
}
//need to pass is word to convert
string toPigLatin(string text)
{
//Figure out how to convert string to pig latin
//need to return string
return text;
}