Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
w3resource

C++ Exercises: Move the first two characters to the end of a given string of length at least two

C++ Basic Algorithm: Exercise-65 with Solution

Write a C++ program to move the first two characters to the end of a given string of length at least two.

Sample Solution:

C++ Code :

#include <iostream>
using namespace std;
string test(string s1)
         {
              string s2=s1;
              return s1.erase(0, 2) + s2.substr(0, 2);
         }
int main()
 {
  cout << test("Hello") << endl;
  cout << test("JS") << endl;
  return 0;
}

Sample Output:

lloHe
JS

Pictorial Presentation:

C++ Basic Algorithm Exercises: Move the first two characters to the end of a given string of length at least two.

Flowchart:

Flowchart: Move the first two characters to the end of a given string of length at least two.

C++ Code Editor:

Contribute your code and comments through Disqus.

Previous: Write a C++ program to concat two given string of length atleast 1, after removing their first character.
Next: Write a C++ program to create a new string without the first and last character of a given string of any length.

What is the difficulty level of this exercise?