CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Threaded View

  1. #1
    Join Date
    Jul 2005
    Posts
    50

    extract the file name and extension from a .txt

    I have a list of files stored in a .txt file

    $codeguru\c++\display.txt$15$

    Directory File Folder: codeguru\c++
    File Name: display.txt
    File Size: 15kbs

    $ is an delimiter

    I want to extract the name and the extension from txt files. Can you give a example of a simple way to do this?

    Code:
    #include <iostream>
    #include <fstream>
    #include <cstdlib>
    
    struct MyFile
    {
    	std::string Directory;
    	std::string Filename;
    	unsigned filesize;
    };
    
    int main()
    {
       std::ifstream readfile ( "mylog.txt");
       if(!readfile)
    	{
    		std::cout << "Please check that the file exists" << std::endl;
    		exit(1);
    	}
       while (!readfile.eof())
       {
    	   //string::find()
              // string::substring()
             // substr or find_last_of   
       }
         // copy all the data to a new file and save it..
    }
    Last edited by jonnybravo; August 10th, 2012 at 01:13 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured