I am taking a dictionary of words from a text file and want to display all the words with four letters.
1 2 3 4 5 6 7 8 9 10 11 12 13
string numWords;
int numLetters;
cout << "Enter number of letters in a word";
cin >> numLetters;
if(numWords.length() == numLetters)
// Iam struck here. Please help if you any alternate code
cout << input << endl;
return 0;
Hint: The following will loop through every space-delimited word in a file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#include <fstream>
#include <iostream>
int main()
{
std::ifstream fin("text.txt"); // assumes you have a file called text.txt filled with words
std::string word;
while (fin >> word)
{
std::cout << word << std::endl;
}
}
Asking the same question several times won't necessarily help you get an answer, and is a time waster for those who respond. Just keep the same topic going.