Hello this is my problem below

How would i do this:

Got a text file called directorycontents.txt in this directorycontents.txt there is a bunch of text each one is a filename with a filename extension i want to be able to go like this if there is a filename extension of specific characters like .txt or .png then do fprintf(stderr,"whateva");

i have looked at istream and fstream and iostream but im not really shore how to use fstream to do this


examples are nice please be simple minded when answer i'm no technical wizard yet.

// reading a text file
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main () {
  string line;// define a string for the line buffer
  ifstream myfile ("example.txt");
  if (myfile.is_open())// Check if the file is open
    while ( myfile.good() )//Check if the state of the stream is good for i/o operations.
	  getline (myfile,line);//get contents of line and put them in the line buffer
	  //looking for .mex
	  cout << line << endl;
  else cout << "Unable to open file"; 
  return 0;

Hope this helps.

Hello thank you so much for that seriously i can learn from this code and do wonders you are a star and deserve a pat on the back! :)