M
MD
Guest
Can you provide me the program for reading file and checking the condition,
condition is if the read file is containing "E "(E space space) then it should print that line and check for next line and print those lines in new output file.
here is the code which i tried
#include <iostream>
#include <string>
#include <fstream>
#include <windows.h>
using namespace std;
void main()
{
int count=0;
string strLine,word,ch;
ifstream inFile;
ofstream outFile;
inFile.open("C:\Documents and Settings\nkhan1\Desktop\test_server.txt");
if(!inFile.is_open())
{
cout<<"Can not open file"<<endl;
}
//for(i=1;!inFile.eof();i++)
//{
while(getline(inFile,strLine))
{
if(strLine.find("E "))
count++;
}
if(count >=1)
{
cout<<"error is displayed"<<endl;
outFile.open("C:\Documents and Settings\nkhan1\Desktop\error_1.txt");
}
/*{
outFile.open("C:\Documents and Settings\nkhan1\Desktop\error_1.txt");
outFile<<strLine<<endl;
}*/
//}
outFile.close();
inFile.close();
}
condition is if the read file is containing "E "(E space space) then it should print that line and check for next line and print those lines in new output file.
here is the code which i tried
#include <iostream>
#include <string>
#include <fstream>
#include <windows.h>
using namespace std;
void main()
{
int count=0;
string strLine,word,ch;
ifstream inFile;
ofstream outFile;
inFile.open("C:\Documents and Settings\nkhan1\Desktop\test_server.txt");
if(!inFile.is_open())
{
cout<<"Can not open file"<<endl;
}
//for(i=1;!inFile.eof();i++)
//{
while(getline(inFile,strLine))
{
if(strLine.find("E "))
count++;
}
if(count >=1)
{
cout<<"error is displayed"<<endl;
outFile.open("C:\Documents and Settings\nkhan1\Desktop\error_1.txt");
}
/*{
outFile.open("C:\Documents and Settings\nkhan1\Desktop\error_1.txt");
outFile<<strLine<<endl;
}*/
//}
outFile.close();
inFile.close();
}