N
nick
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_type posn;
if (textfile.is_open())
{
while (getline(textfile, text))
{
posn = text.find("red");
if (line.search(red) != 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;
}
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_type posn;
if (textfile.is_open())
{
while (getline(textfile, text))
{
posn = text.find("red");
if (line.search(red) != 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;
}