470,855 Members | 1,172 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,855 developers. It's quick & easy.

checking for a word in a line(using getline) read from a text from a file using C++

I have written a program which executes an application (netview) and logs the output into a text file.Later I open and read this file line by line using getline() function.Now I need to check whether a particular word exists in the line read from the text file.Plz help...

Below is my coding:

#include <stdio.h>
#include <dos.h>
#include <stdlib.h>
#include <time.h>
#include <conio.h>
#include <iostream>
#include <fstream>
#include <string>

using namespace std;

FILE *fp;

char fln[100]="net view >test.txt";

char fln2[100];



void main()
{

for(;;)
{



fp = fopen("create_dir.bat","w");
sprintf(fln2,"@echo OFF\n %s",fln);
fputs(fln2,fp);
fclose(fp);
system("create_dir.bat");
system("del create_dir.bat");



string line;


ifstream myfile ("test.txt");
if (myfile.is_open())
{
while (! myfile.eof() )
{

getline (myfile,line);


cout <<line<<endl;

}

myfile.close();
}


else cout << "Unable to open file";



}





}


Thank You,
Rajeev Nair.
Jun 9 '06 #1
1 4819
Banfa
9,065 Expert Mod 8TB
Look up the method

string::find
Jun 10 '06 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

7 posts views Thread by MouseHart | last post: by
2 posts views Thread by I_AM_DON_AND_YOU? | last post: by
3 posts views Thread by Phoe6 | last post: by
8 posts views Thread by John Salerno | last post: by
4 posts views Thread by Alexander Vasilevsky | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.