Write a C++ program to create a new string without the first and last character of a given string of length atleast two

  • برمجة سي بلس بلس
  • برمجة

Write a C++ program to create a new string without the first and last character of a given string of length atleast two

Sample Output:

ell

ytho

الأجوبة

#include <iostream>
using namespace std;

string test(string s1)
            {
             return s1.substr(1)
                .substr(0, s1.length() - 2);
         }
         
int main() 
 {
  cout << test("Hello") << endl;  
  cout << test("Hi") << endl; 
  cout << test("Python") << endl;   
  return 0;    
}
هل كان المحتوى مفيد؟

تبحث عن مدرس اونلاين؟

محتاج مساعدة باختيار المدرس الافضل؟ تواصل مع فريقنا الان لمساعدتك بتأمين افضل مدرس
ماهو التخصص الذي تبحث عنه؟
اكتب هنا...