I am currently stuck with a slight problem where I want to swap contents in a std::string.
#include <iostream>
#include <string>
void swap(char* t1, char* t2); // function parameter is wrong syntax
int main(){
std::string message = "ABC";
swap(message[0], message[1]); // parameter probably wrong here
return 0;
}
void swap(char * t1, char * t2){
return;
}
GOAL: I wish to do a simple swap of the contents in index 0 and 1 such that after swapping it, the message "ABC" becomes "BAC". As you can see, I tried doing it like I was using a normal array, but it seems this logic doesn't work with strings. I understand that if I switch to
char a[] = "ABC";
it would work, but I wanna try it using the string class.