How to reverse the first N characters in the string with C++

1 Answer

0 votes
#include <iostream>
#include <string>
#include <algorithm>

using std::cout;
using std::endl;

int main()
{
	std::string s = "abcdefg";
	int N = 5;

	std::reverse(s.begin(), s.begin() + N);
	
	cout << s << endl;

	return 0;
}

/*
run:

edcbafg

*/

 



answered Jun 16, 2018 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
...