How to check if string ends with .txt

后端 未结 11 1804
耶瑟儿~
耶瑟儿~ 2020-12-15 04:23

I am learning basic C++, and right now I have gotten a string from a user and I want to check if they typed the entire file name (including .txt) or not. I have the string,

11条回答
  •  无人及你
    2020-12-15 05:03

    bool has_suffix(const std::string &str, const std::string &suffix)
    {
        std::size_t index = str.find(suffix, str.size() - suffix.size());
        return (index != std::string::npos);
    }
    

提交回复
热议问题