Computer Science, asked by bichugang183, 10 days ago

Write a program in which, you have to get an input from user into a character array search the array
from file "word.txt" and if you found the occurrence than display true else false
word.txt
Hello
Happy
Hello
Input
Happy
Output: true​

Answers

Answered by dreamrob
0

Program in C++

#include<iostream>

#include<fstream>

#include<string>

using namespace std;

int main()

{

ofstream f_1("word.txt");  

f_1<<"Hello\nHappy\nHello";

f_1.close();

 

ifstream f1("word.txt");

string search;

cout<<"Enter word to be searched : ";

cin>>search;

string ans = "false";

while(!f1.eof())

{

 string temp = "";

 getline(f1 , temp);

 for(int i = 0 ; i < search.size() ; i++)

 {

  if(temp.compare(search)==0)

  {

   ans = "true";

   break;

  }

 }

}

cout<<ans;

f1.close();

return 0;

}

Output:

Enter word to be searched : Happy

true

Similar questions