Basically, my program will open the file "word.dat" and it will count and remove all the vowel to store it into another file called "text.out". However, I cannot seem to make it work because when I run the program it will only output the last sentence of "word.dat". Also, is it possible to show how many sentence it contains in the file? Any help or tips are appreciate, thank you in advance.
#include<iostream>
#include<string>
#include <fstream>
using namespace std;
int main()
{
ifstream file;
File.open("word.dat");
if (!File)
{
cout << "Unable to open file!" << endl;
return 0;
}
string sentence;
while (File >> sentence);
{
string newstring;
int j, a = 0, e = 0, i = 0, o = 0, u = 0;
for (j = 0; j < sentence.length(); j++)
{
if (sentence[j] == 'a' || sentence[j] == 'A')
{
a++;
}
else if (sentence[j] == 'e' || sentence[j] == 'E')
{
e++;
}
else if (sentence[j] == 'i' || sentence[j] == 'I')
{
i++;
}
else if (sentence[j] == 'o' || sentence[j] == 'O')
{
o++;
}
else if (sentence[j] == 'u' || sentence[j] == 'U')
{
u++;
}
else (newstring += sentence[j]);
}
ofstream outfile;
outFile.open(file.text);
outFile << "\nThe sentence *" << sentence << "* with vowel removed is : " << newstring;
outFile.close();
cout << "\nthe number of vowel removed are : " << endl << " a :" << a << endl << " e :"
<< e << endl << " i :" << i << endl << " o :" << o << endl << " u :" << u << "\n" << endl;
inFile.close();
}
return 0;
}