GLProgramming.com

home :: about :: development guides :: irc :: forums :: search :: paste :: links :: contribute :: code dump

-> Click here to learn how to get live help <-


New Paste :: Recent Pastes:: No Line Numbers


A Paste by godecho
1
 
#include <iostream>
#include <fstream>
#include <set>
#include <string>

typedef std::set<std::string> Dictionary;

void lookup(const Dictionary& Set, const std::string& word)
{
    Dictionary::const_iterator it = Set.find(word);
    std::cout << word << ": " << (it != Set.end() ? "present" : "not present") << std::endl;
}                               
                                
int main()                      
{                               
    Dictionary set;

    std::ifstream file("file.txt");
                                
    std::string str;
    
    while(getline(file, str))             
    {                           
        if(str.length() != 0)
        {                       
            std::cout << "inserting " << str << " in dict" << std::endl;
            set.insert(str);       
        }                       
    }                           
                                
    file.close();

    std::string word("lol");
                                
    lookup(set, word);
}