+ 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 ?!
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.
0
thanks @Ripper