#include <iostream>
void ReverseStringWithoutTemporaryVariable(std::string &str) {
int start = 0, end = str.length() - 1;
while(start < end) {
str[start] ^= str[end]; // XOR used to swap two variables
str[end] ^= str[start];
str[start] ^= str[end];
start++;
end--;
}
}
int main() {
std::string str = "c++ java c";
ReverseStringWithoutTemporaryVariable(str);
std::cout << str;
}
/*
run:
c avaj ++c
*/