My question is simple, but I can't seem to find the answer anywhere. I am checking for \n char's in my program as I read in characters, but my program does not seem to detect them. As can be seen, I stay in the while loop even though there is the condition (input != \'n'). This is even though my input file has plenty of new lines. As a result, the whole string gets interpreted as one word.
ifstream d_file;
char input = '\0';
string word;
d_file.open(dict_file);
d_file >> input;
//declares string for characters to be put into
while ( !d_file.eof())
{
//reinitializes the word
word = "";
while (input != '\n' && !d_file.eof())
{
cout << "\n";
putchar (tolower(input));
//appends the string with characters
word+=input;
d_file >> input;
}
dictionary.insert(word);
d_file >> input;
cout << word << " ";
}
d_file.close();
as can maybe be seen, I don't want all one word together and then a space. I want word separated by spaces at the end.
Aucun commentaire:
Enregistrer un commentaire