Suppose I have an external while loop to read each character and output it to the console. I also want to mark the word if it is found, and with the peek method I can find the first instance of the word. Is there a way to look a few places ahead. For example, if I search for the word "payday". I know that I can type this into a string and search for a string, but I want to read files in binary mode, and I don't want to remove any values from the outer loop. If I have an inner loop with a read method, these values are then not displayed through the outer loop.
thanks
int main()
ifstream strm;
char *chr = new char;
strm.open("mytext.txt",ios::out | ios::binary);
while (strm.read(chr,1)
{
if (strm.peek() == 'p';
{
cout << "found a word beginning with 'p'" << endl;
}
}
source
share