First you have to extract a word from your text file.
Second compare it with the word you want to search.
true?-->found!
false?-->extract the next word from the file and compare again etc.
until the end of file is reached.
ddanbe
Senior Poster
3,829 posts since Oct 2008
Reputation Points: 2,070
Solved Threads: 661
C++ has a string class which contains a compare method. You certainly have some documentation where you can get info about those. If you can find it you can even do better.
ddanbe
Senior Poster
3,829 posts since Oct 2008
Reputation Points: 2,070
Solved Threads: 661
You could use tags. For example:
//Proper libaries//
...
ifstream infile("text.txt")
ofstream outfile("search.txt")
...
...
...
bool tag=flase;
char Word[500];
//Searches word by word;
do
{
cin.getline(Word,500)
//check if word matches;
if(word[500]=="your word"
{
tag=true;
break;
}
} while(!infile.eof());
//So basically search the whole file and keep tab on which word you have imported and if your word matches then, break;
firstPerson
Senior Poster
3,923 posts since Dec 2008
Reputation Points: 841
Solved Threads: 608
C++ has a string class which contains a compare method. You certainly have some documentation where you can get info about those. If you can find it you can even do better.
I can understand that is is all new to you, and that it is difficult to grasp it all, but why use char array when there is a string class? Why do you refuse to read or look up documentation?
You do#include so why don't you use it?
ddanbe
Senior Poster
3,829 posts since Oct 2008
Reputation Points: 2,070
Solved Threads: 661