Help about making directory and write files into that

Discussion in 'C++' started by sitha, Nov 15, 2006.

  1. sitha

    sitha New Member

    Nov 15, 2006
    Likes Received:
    Trophy Points:
    Hi Everybody,
    I am little new to C++ program. I want to write a program which could be able to read data from files which is in a folder.
    Following my program could be able to read all data in files.
    Now say each files has 10 lines of data.
    My program should read each files first line data and put it into a folder in a file, name result1, then it should read second data of each files and put it into the folder with file name result2. and so on................

    This is my code,
    [B]int printFiles(char * dirname)
       char* POV;
       DIR* dirp;
       string buff;
       struct dirent* dp;
       [COLOR=Navy]system("mkdir POV"); [/COLOR] 
       ofstream output("test.pov");
       [COLOR=Green]dirp = opendir(dirname);[/COLOR]
       if ( !dirp )
          cout << "Error: failure opening directory" << endl;
       errno = 0;
       [COLOR=Green]while ( dp = readdir(dirp) )  {[/COLOR]
    	   if(dp !=NULL) {
          if(strstr(dp->d_name, ".dat"))  {
             ifstream input(dp->d_name);        
             while( getline(input, buff) )
                cout << buff << endl;
                output<< buff << endl;
          if ( errno )
             cout << "Error: readdir() failure!" << endl;
       closedir( dirp );
    Here I dont know how to read each files data and put them into corresponding files.

    Pls help me.


Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice