**hello every body i am trying to filter alog file witch is save as txt file on my computer so i want to filter the log file depend on a particular word and this word apper in 3 column but the column i want is th 3rd one for example ,now i know that i must use the split function but i cant figure how i must use it i will atatch my code mybe you can understand it and help me to make it work **
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main()
{
string temp[100]; // temporary array to store strings for each line
int column=0;
ifstream file1;
ofstream file2 ;
char read[1000];
file1.open("d:\h1.txt");
file2.open("d:\learningsplit.txt");
if(!file1)
{
cout<<endl<<endl<<endl;
cout<<" This file1 CANNOT be opened .";cout<<endl;
}
if(!file2)
{
cout<<endl<<endl<<endl;
cout<<" This file2 CANNOT be opened .";cout<<endl;
}
int line=1;
while(!file1.eof())
{
string x;
getline(file1,x); // Get the content of the line from the read file and put it inside "read" array.
string s=x; // the previous is a sample string, it is a line from log file
// start of the code to split and store in array each column is stored at location column-1 in the temp array
string::size_type prev_pos = 0, pos = 0;
while( (pos = s.find('\t', pos)) != std::string::npos )
{ column++;
string substring( s.substr(prev_pos, pos-prev_pos) );
temp[column-1]=substring;
prev_pos = ++pos;
}
string substring( s.substr(prev_pos, pos-prev_pos) ); // Last word
temp[column]=substring;
// to test the code
for (int i=0; i<column; i++)
cout<<temp[i]<<'\t'<<i+1<<endl;
// end of split ioperation for a single line
//NOW YOU HAVE YOUR ENTIRE ROW STORED SEPARATELY IN AN ARRAY INDIXED BY COLUMN NUMBER-1
//YOU CAN ACCESS EACH SRTING SEPARATELY AND USE IT IN COMPARISON FOR FILTERING.
// printing array of contents , THIS IS JUST A TEST
}
**thes is the word i want filter the file according to it //line=temp[i].find("hebron");**
// if(line>0)
// {file2<<x<<"\n"; // Write the contents of the line to the output file.
//
file2.close(); // Close the output file to save the changes.
cout<<endl<<endl;
cout<<" Reading is done successfully ! "<<endl;
getchar();
return 0;
}
please help me very soon i need the helpe befor this sundy :)