I have the text file (in1.text)
<<<start>20>>everything going fine or not<start>i do not know but I am trying<end><start>Trying is but we can do<startabcdefghijklmnopqrstuvwxyz<end>
<<<start>20>>Trying to do things<end><<<start>20>>well try try and try again<end>
I have to extract tag <<<start>20>> from file.My code is
#include <vector>
#include <fstream>
#include <sstream>
#include <iostream>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
std::ifstream fin;
fin.open("in1.txt");
static int pos;
int array[10];
if (fin) {
std::stringstream ss;
ss << fin.rdbuf();
std::string contents = ss.str();
for(int i =0,search;(search= contents.find("<<<start>", i))!= string::npos;i= search + 1)
{
start[search] = "<<<start>";
array[pos]=search;
pos++;
}//end for
for(int itr=0;itr<=pos;itr++)
{
int number=array[itr];
string substring=contents.substr(number,number+13);
cout<<substring<<"\n";
number=0;
}//end for
}//end fin
}//end main
The code is giving output
[replyfast@localhost NEW]$ ./a.out
<<<start>20>>
<<<start>20>>i am all right ,just trying to do things<end><<<start>20>>well try try and try again<end>
<<<start>20>>well try try and try again<end>
Aborted
The first output is ok,but subsequent output gives some additional lines.How to rectify code so that it gives only <<<start>20>>
I am working on redhat linux(g++ compiler)
Regards
replyfast