#include <iostream>#include <string>using namespace std;bool endWith(string str, string suffix) { int a = str.length(); int b = suffix.length(); if (a < b) return false; for (int i = 0; i < b; i++) { if (str[a - i - 1] != suf...
摘要由CSDN通过智能技术生成
#include<iostream>#include<string>usingnamespace std;boolendWith(string str, string suffix){
int a = str.length();int b = suffix.length();if(a < b)returnfalse;for(int i =0; i < b; i++){
if(str[a - i -1]!= suffix[b - i -1])returnfalse;}returntrue;}intmain(){
string a, b;
cout <<"Enter a text: ";getline(cin, a);
cout <<"Enter a suffix: ";getline(cin, b);if(endWith(a, b)){
cout <<"True"<< endl;}else
cout <<"False"<< endl;return0;}
#include<iostream>#include<string>usingnamespace std;
string trim(string& str){
for(int i =0; i < str.length(); i++){
if(isspace(str[i])){
str = str.replace(i,1,"");--i;}}return str;}intmain(){
string a;
cout <<"Enter a text: ";getline(cin, a);trim(a);
cout << a << endl;return0;}
#include<iostream>#include<string>usingnamespace std;
string substring(string str,int pos,int n ){
string newstring ="";if(pos > str.length()){
cout <<" Wrong position."<< endl;}if( n >(str.length()
#include <iostream>#include <string>using namespace std;bool endWith(string str, string suffix) { int a = str.length(); int b = suffix.length(); if (a < b) return false; for (int i = 0; i < b; i++) { if (str[a - i - 1] != suf...