Ел
Елена

Вывести строку "задом наперед". C++

Ввести с клавиатуры произвольную строку символов. Найти и вывести длину строки.
Вывести строку "задом наперед".

ИБ
Ирина Быкова

если это Си-строка, то
for( int i = size-2; i > -1; i++ ) cout << str[ i ] ;

БД
Бахтиер Джабборов

/*
* Вывести строку "задом наперед". C++
* strreverse.cpp
*
* Copyright 2017 Denis Trofimov
* github.com/denis-trofimov
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*
*
*/

#include iostream
#include string

using namespace std;

void swap_by_reference(auto& a, auto& b)
{
a^=b;
b^=a;
a^=b;
}

void strreverse(string& str)
{
const unsigned len = str.size();
for(unsigned i=0; i {
swap_by_reference(str[i], str[len-1-i]);
}
}

int main(int argc, char **argv)
{
cout << "Введите строку:";
string in_str = "";
cin >> in_str;
cout << "\nOK.";
strreverse(in_str);
cout << "\nСтрока задом наперед: \"" << in_str << "\".";

return 0;
}

Пионерский вариант будет таким, возьмите iostream и string как в кавычки больше меньше <>:

#include iostream
#include string

using namespace std;

void strreverse(string& str)
{
const unsigned len = str.size();
for(unsigned i=0; i {
unsigned char temp = str[i];
str[i] = str[len-1-i];
str[len-1-i] = temp;
}
}

int main(int argc, char **argv)
{
cout << "Введите строку:";
string in_str = "";
cin >> in_str;
cout << "\nOK.";
strreverse(in_str);
cout << "\nСтрока задом наперед: \"" << in_str << "\".";

return 0;
}

Похожие вопросы
C# работа со строками
Проблема с строками в C++
Как лучше, по спирали вперед, или по кругу задом-наперед?
Эксель. Нет ли стандартной функи инвертировать текст задом наперед? Самому писать?
Ввести строку, вывести самое длинное слово. с++. Ввести строку, вывести самое длинное слово. с++
Работа со строкой в c++
Библию надо читать задом наперед?
Чем пахнет мода, если ее прочитать задом наперед?
А что, если посмотреть фильм "Золушка"задом наперед?
c# надо объяснить строки