+ 1

How can i make a shift left operation on a(string 'char)

ex: the string(ahmed) by making shift left(<<3)operation i want to get (ed) only ?!

4th Dec 2016, 8:45 PM
Ahmed Mansy
Ahmed Mansy - avatar
2 odpowiedzi
0
Just use substr. For your example that will look smth. like this: string str ="ahmed"; cout<<str.substr(3,2); // this will print ed The 3 means you start from the 3rd char and you save the next 2 values. And here you have a general form: cout<<str.substr(3, name.length() - 3); This will 'shift' any string with 3 positions. Just replace the 3s with 4s and it will 'shift' with 4 positions.
4th Dec 2016, 10:58 PM
Ripper
Ripper - avatar
0
thanks @Ripper
5th Dec 2016, 12:47 AM
Ahmed Mansy
Ahmed Mansy - avatar