W
Wilson
hi, one aspect of a program i am creating needs to extract a certain
line of text from a simple ".txt" file. However i can only find a way
of extract everything present in the file using i/o streams. Below is
the code i used to extract the whole text, is there any way of
extracting a certain line or sentance?
string line;
ifstream myfile ("example.txt");
if (myfile.is_open())
{
while (! myfile.eof() )
{
getline (myfile,line);
cout << line << endl;
}
myfile.close();
}
using the header files
#include <iostream>
#include <fstream>
#include <string>
line of text from a simple ".txt" file. However i can only find a way
of extract everything present in the file using i/o streams. Below is
the code i used to extract the whole text, is there any way of
extracting a certain line or sentance?
string line;
ifstream myfile ("example.txt");
if (myfile.is_open())
{
while (! myfile.eof() )
{
getline (myfile,line);
cout << line << endl;
}
myfile.close();
}
using the header files
#include <iostream>
#include <fstream>
#include <string>