fork(1) download
  1. #include <iostream>
  2. #include <fstream>
  3. #include <sstream>
  4. #include <string>
  5. #include <iterator>
  6. #include <algorithm>
  7.  
  8. using namespace std;
  9.  
  10. int main() {
  11. cout<<"Enter a word to be searched in the file words.txt:";
  12. string wordForQuery;
  13. cin>>wordForQuery;
  14. // no files on ideone.com, using string
  15. string inFile_contents = "there are some words in this file\nthat can be searched";
  16. istringstream inFile(inFile_contents);
  17. // ifstream inFile("words.txt");
  18. istream_iterator<string> beg(inFile), end;
  19. if(find(beg, end, wordForQuery) != end)
  20. cout << "Found!\n";
  21. else
  22. cout << "Not Found!\n";
  23. }
Success #stdin #stdout 0s 2864KB
stdin
foo
stdout
Enter a word to be searched in the file words.txt:Not Found!