Nothing prints, even a simple cout statement outside of this loop?

by Zranzax   Last Updated March 14, 2019 20:26 PM

I have a quick question on this code I'm working on. I'm trying to get a set of ints that act as possible word lengths from a dictionary text file I've been given. However, while the code seems to run, nothing ever gets printed. Including if I put a simple cout statement at the beginning of the code, nothing gets outputted. I have never seen something like this before and don't know what to google since I'm not getting an error code or anything. Some guidance would be greatly appreciated! Here's my main.cpp:

#include <iostream>
#include <set>
#include <fstream>
int main() {
    int wordLength = 0;
    std::string currentWord;
    std::ifstream myStream("dictionary.txt");
    std::set<int> possLengths;
    while(!myStream.eof()) {
        myStream >> currentWord;
        possLengths.insert(currentWord.length());

    }
    std::cout << "Welcome to hangman!" << std::endl;
    while(possLengths.count(wordLength) == 0){
        std::cout << "Please enter a length for your word." << std::endl;
        std::cin >> wordLength;
        if(possLengths.count(wordLength) == 0) std::cout << "Sorry, I don't know any words of that length" << std::endl;
    }
    return 0;
}

And then the dictionary.txt is just a little under 130,000 lines with each line containing a unique word. If anyone could offer help, I'm really out of options.

Tags : c++ set


Related Questions