How to reverse the first N characters of a string in C++

1 Answer

0 votes
#include <bits/stdc++.h> 

using namespace std;

int main() 
{ 
    string s = "c++ programming"; 
    
    int len = s.length(); 
    int pos = 3;
    
    reverse(s.begin(), s.begin() + pos); 
    
    cout << s;
  
    return 0; 
} 



/*
run:

++c programming

*/

 



answered Jun 24, 2019 by avibootz

Related questions

1 answer 177 views
1 answer 217 views
1 answer 160 views
1 answer 166 views
1 answer 174 views
1 answer 188 views
1 answer 140 views
...