0

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

thanks

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

Edited by dakerao: n/a

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by dakerao
0
// 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
	  if(line.find(".mex")!=string::npos)
	  cout << line << endl;
    }
    myfile.close();
  }
  else cout << "Unable to open file"; 
  cin.get();
  return 0;
}

Hope this helps.

0

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! :)

Edited by dakerao: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.