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

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

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

Try to use tokens
result = strtok( line, "*" );

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;
}
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.