0

need some idea from to find the same word in text file example i had a list of word in text file,let me name it noun.txt..contain noun word..the file contain like this

walk
run
eat
drink
....


give me an idea how can i find word eat in the noun.txt

i know that i can use strcmp..but how..must think...

anyway, thank you

4
Contributors
4
Replies
6
Views
12 Years
Discussion Span
Last Post by Bench
0

i had open the file using

fstream file;
file.open("katakerja.txt");

now must think how to read the string from the file..wish me luck

0

while file is open
do{
ch = the string
string compare ch with "eat"
if ch == eat
stop
}
close the file

0

in C++, I always try to use library functions, thereby avoiding potentially haphazard loops. for example:

void FindEat(std::string in)
{
    std::string match("eat");
    if (match==in)
        std::cout << "Match found \n" ;  
}

int main()
{
    std::ifstream verbs("verbs.txt");
    if (verbs)
    {
        std::istream_iterator<std::string> start(verbs), finish;
        std::for_each(start, finish, FindEat);
    } else
        std::cout << "error!";
    return EXIT_SUCCESS;
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.