Hi all
can any one please tell me what is wrong in this code??
I'm new to deal with text files and extract data.
i'm trying to look for data in a text file (3~4 pages) some lines start
with a word "red" first if find(red) then print the last 5 letters of
that string and if red is not found at the begining of the string then
do nothing and
go to another line.
how can I also do this using find( )??
thanks
#include <iostream>
#include <fstream>
#include <string>
int main( )
{
ifstream textfile ("textfile.txt" );
string text;
string::size_ty pe posn;
if (textfile.is_op en())
{
while (getline(textfi le, text))
{
posn = text.find("red" );
if (line.search(re d) != std::string:no_ pos)
//if (posn == string::npos)
{
continue;
}
std::string data = text.substr(5);
cout<<" " << data << endl;
}
}
else cout << "can't open file" << endl;
system("PAUSE") ;
return EXIT_SUCCESS;
}
Comment