Hi,
I want to ask if there function in library of c++ to search word in file ??
thank you
Not that I know of. You have to read some (all) of the file, then search using any of several possible methods.
If you expand on your problem definition, and show the work you've done to solve it, you will get better help here.
Please read the forum rules.
Val
>I want to ask if there function in library of c++ to search word in file ??
No. You need to break it down into smaller operations like reading a file and searching a string for a word. Then you can do this:
std::ifstream in ( "myfile" );
if ( in ) {
bool found = false;
std::string search_for = "teapot";
std::string word;
while ( in>> word ) {
if ( word == search_word ) {
found = true;
break;
}
}
//...
}
Or this:
std::ifstream in ( "myfile" );
if ( in ) {
bool found = false;
std::string search_for = "teapot";
std::string line;
while ( std::getline ( in, line ) ) {
if ( word.find ( search_word ) != std::string::npos ) {
found = true;
break;
}
}
//...
}
For example.
thank you
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.