Answers for "c++ endswith"

C++
0

c++ endswith

#include <iostream>
using namespace std;

inline bool endsWith(string const &value, string const &ending)
{
    if (ending.size() > value.size()) return false;
    return equal(ending.rbegin(), ending.rend(), value.rbegin());
}

int main() {
	string teststring = "This should return true because the string ends with a period.";
    string ending = ".";
      
	cout << endsWith(teststring, ending);      
}
Posted by: Guest on March-25-2021

Browse Popular Code Answers by Language