473,516 Members | 2,889 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

1 New Member
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 4994
Banfa
9,065 Recognized Expert Moderator Expert
Look up the method

string::find
Jun 10 '06 #2

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

Similar topics

7
5706
by: MouseHart | last post by:
I have written a small VB program which lists my music files on my computer, but I can't get it to print exactly the way I want it to. The data is viewed on screen in an MSFlexGrid named "TextGrid" and the following code will send it to a printer, but I was hoping to be able to send it to either a text file or directly to a Word for Windows...
2
1807
by: I_AM_DON_AND_YOU? | last post by:
Can BinaryReader Object read the Word file?
8
2120
by: MLH | last post by:
Am trying to import 20,000+ lines of text in a file FTP'd from a UNIX platform to windows via FTP session in a DOS box. About 2000 records have multiple lines in them separated by CRLF's. That's not the idea. Each line was supposed to be a separate record. I don't know why the 2000 records having MULTIPLE lines of text are so stubborn....
3
8876
by: Phoe6 | last post by:
Hi all, I just read the manual and got to know I can use a for loop to iterate through the lines in the file. But so far, I was strugling with the following: import os file = open('File1.txt','r') line = file.readline() while line !=' ':
8
4199
by: John Salerno | last post by:
I figured my first step is to install the win32 extension, which I did, but I can't seem to find any documentation for it. A couple of the links on Mark Hammond's site don't seem to work. Anyway, all I need to do is search in the Word document for certain strings and either delete them or replace them. Easy enough, if only I knew which...
4
5034
by: kdsutaia | last post by:
hi! I am trying to read file line by line using BufferReader class.Following I have written to read but some how for few of the file it is not reading the whole file. Can any help me to resolve this or suggest me the best apporch to read line by line from given file ? try { br = FileRead.readTOLine(path ,filename); while ((line...
4
1776
by: Alexander Vasilevsky | last post by:
Need to read Word file without Office installation. It's possible? http://www.alvas.net - Audio tools for C# and VB.Net developers
0
917
by: yazhen | last post by:
Can somebody tell me how to read/ display the content of microsoft word file in ASP.net web form, and able to genearate smart menu on fly when mouse over the content. The content of file may include images. Thanks !!!!
1
1708
by: hmkaddoura | last post by:
Hi... is there a way to use the find exact match from MS word in my vb.net? I want to open a MS word file in my vb.net and I want to find the exact word in the field text in the word file. Regards HK
0
7276
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7182
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7408
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7142
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7548
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
4773
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3259
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
825
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
488
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.