How to swap characters in string with C++

1 Answer

0 votes
#include <iostream>

int main(void) {
   std::string s = "c++ programming";
   
   std::cout << s << "\n";
 
   std::swap(s[1], s[5]);
   
   std::cout << s;
 
   return 0;
 
}
 
 
 
 
/*
run:
 
c++ programming
cr+ p+ogramming
 
*/

 



answered Feb 16, 2021 by avibootz

Related questions

1 answer 117 views
1 answer 147 views
1 answer 116 views
1 answer 91 views
1 answer 112 views
112 views asked Nov 22, 2022 by avibootz
1 answer 110 views
3 answers 260 views
...