View Single Post
Join Date: Oct 2006
Posts: 2,753
Reputation: niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute 
Solved Threads: 294
Featured Poster
niek_e's Avatar
niek_e niek_e is offline Offline
Posting Maven

Re: Compare a string with a file.

 
0
  #2
May 11th, 2008
Originally Posted by tharris7 View Post
char dictword[32];    
}
Why use char arrays when c++ provides you with strings? Mixing up C and C++ is very confusing and will require a lot of casting. So what about something like:
  1. string word = "abc";
  2. string dictword;
  3. ifstream dictionary("dictionary.txt");
  4. while (getline(dictionary, dictword, ' '))
  5. {
  6. if (word == dictword)
  7. cout << "found: " << word << "\n";
  8. }
Off course you'll have to build in some error checking etc. And this code assumes that all words in textfile are delimited with a space. So some more work is required from you
Last edited by niek_e; May 11th, 2008 at 7:20 am.
Reply With Quote