Posted by MindBreaker at 7:57 AM
Read our previous post
Object:
How to search the text or particular word from text file in c++.
Source code:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
ifstream readFile.open("<insert the name of your file here>"); //
string word; // will hold a single word from the file
bool found = false; //determines if a word was found
// To search for a particular word, in example, "Bob"
while( readFile >> word )
{
if( word == "Bob"){
cout <<"The word has been found." << endl;
found = true;
}
}
if( bool = false)
cout <<"The word wasn't found." << endl;
return 0;
}
How to search the text or particular word from text file in c++.
Source code:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
ifstream readFile.open("<insert the name of your file here>"); //
string word; // will hold a single word from the file
bool found = false; //determines if a word was found
// To search for a particular word, in example, "Bob"
while( readFile >> word )
{
if( word == "Bob"){
cout <<"The word has been found." << endl;
found = true;
}
}
if( bool = false)
cout <<"The word wasn't found." << endl;
return 0;
}
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.