首页 > 解决方案 > 如何用文件的类型初始化一个类

问题描述

我是一个初学者,我不知道如何处理这个任务:

   *This class is intended to be instantiated with a src character string as a parameter of its constructor. It must then:
   *-> Determine the type of file to which src corresponds (among: image, video, security plan [.mps]), using the extension
   *-> Check if the file corresponding to src exists.
   *-> If the file does not exist, the src member variable of File is initialized with a path to a file by default, depending on the type
   *(if the desired file was an image, src will contain the path to an "Error" image, ditto for videos and mps).

在 File.h 中:

        class File{
        private:
            string src;
            string type;
        
        public:
            string description;
        
            File();
            File(string src);
           ~File();
            bool exists();
    };

在 File.cpp 中:

File::File(string src):src(src){}

bool File::exists(){}

问题是我不知道如何从字符串中检查文件的扩展:/。

标签: c++

解决方案


推荐阅读