Witam. Mój program ma przyjąć string, odwrócić go i wydrukować. Zadanie mówi o użyciu "pointer increment during the copy" czy ktoś może podpowiedzieć mi w jaki sposób?
#include <string>
#include<iostream>
using namespace std;
void reverseStr(string& str) // this function reverses the string
{
int n = str.length();
for (int i = 0; i < n / 2; i++) //it swaps characters of two ends
{
swap(str[i], str[n - i - 1]);
}
}
int main()
{
char run_me_again_check; // for mutiple running of program
bool run_me_again = true;
while (run_me_again )
{
cout << "Please enter the string to reverse : ";
string str;
cin >> str;
reverseStr(str);
cout << str <<endl;
cout << "One more time? (Y/N) ";
cin >> run_me_again_check;
if (run_me_again_check == 'Y' || run_me_again_check == 'y')
{
run_me_again = true;
}
else
{
run_me_again = false;
}
}
system("pause");
return 0;
}