Click here to Skip to main content
14,690,983 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a text file with some content i need to search the file for a word and have to write the complete line in which my search word is found to another text file.

i am using ifstream to open the file but unable to search the file for the text.
Posted

1 solution

Read a line at time using getline[^], then use string::find[^] to search for the word in the line.
   
Comments
Member 11648410 11-Aug-15 8:14am
   
when ever i use getline it shows getline() undeclared identifier

FILE *fp;
fp = fopen("address.txt","a");
char str[1024];
getline(fp,str);

i have these header files
string,iostream,fstream
CPallini 11-Aug-15 13:01pm
   
getline takes an istream object, not a FILE pointer. Create an ifstream instance instead of using fopen
Member 11648410 12-Aug-15 1:18am
   
thank CPallini ...... i have created ifstream and it worked
CPallini 12-Aug-15 2:29am
   
You are welcome.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900