can anyone help me!? i have to create program to search word from text file, but i don't know how can i match word from input to text.. Can anybody help!!!??
ojung -5 Newbie Poster
Recommended Answers
Jump to Post— ddanbe 2,724First 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.
Jump to Post— ddanbe 2,724C++ 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.
Jump to Post— mrnutty 761You 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 …
Jump to Post— Freaky_Chris 299My advice, do not use eof() it's counter productive. Instead do this.
while(getline(file, someString)){ //yourcode }Chris
All 15 Replies
ddanbe 2,724 Professional Procrastinator Featured Poster
ojung -5 Newbie Poster
ddanbe 2,724 Professional Procrastinator Featured Poster
mrnutty 761 Senior Poster
ojung -5 Newbie Poster
swyncoop 0 Newbie Poster
Freaky_Chris 299 Master Poster
Member #46692 commented: Amen +17
ojung -5 Newbie Poster
Freaky_Chris 299 Master Poster
ojung -5 Newbie Poster
ddanbe 2,724 Professional Procrastinator Featured Poster
ojung -5 Newbie Poster
ojung -5 Newbie Poster
Salem commented: 10+ posts, still hasn't figured out code tags - a lost cause -5
dougy83 74 Posting Whiz in Training
onksssss 0 Newbie Poster
jonsca commented: Don't bump old threads +0
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.