View Single Post
Join Date: May 2008
Posts: 1
Reputation: tharris7 is an unknown quantity at this point 
Solved Threads: 0
tharris7 tharris7 is offline Offline
Newbie Poster

Compare a string with a file.

 
0
  #1
May 11th, 2008
Hi,

I'm quite new to C++ so all help is appreciated.

I have a program that makes a string of at least three characters. I want to be able to compare the string to a list of words (i.e. dictionary) in a separate file, and then output the string if it is in the dictionary.

The string 'word' is a string object so I'm having problems with strcmp (which only takes chars?). The reason I used a string object is because I have to use substr and concatenation, and I'm not very familiar with using char arrays. (I've mostly done Java before).

What I have got so far:

char dictword[32];    
ifstream dictionary("dictionary.txt");

while (dictionary>>dictword)
{      
        if (strcmp(dictword,word)!=0)
   		cout<<word<<'\n";
}

Thanks in advance,
Tim
Reply With Quote