Language: C++


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <sstream>

using namespace std;

typedef vector<string> StringList;

class Transformation
{
public:
    static void exeOrder(const string &src, const StringList &order)
    {
        int a = stoi(order[1]);
        int b = stoi(order[2]);
        if(order[0] == "print")
        {
            cout << src.substr(a, b) << endl;
        }
        else if(order[0] == "reverse")
        {
            reverse(src.begin() + a, src.begin() + b);
        }
        else if(order[0] == "replace")
        {
            src = src.substr(0, a) + order[3] + src.substr(b+1);
        }
    }


};


int main()
{
    string str;
    cin >> str;

    string buf;
    cin >> buf;
    int n = stoi(buf);
    for(int i = 0; i < n; i++)
    {
        getline(cin, buf);
        stringstream ss(buf);

        StringList list;
        string tmp;
        while(getline(ss, tmp, ' '))
        {
            list.push_back(tmp);
        }
        Transformation::exeOrder(str, list);

    }

    return 0;
}

Compiler output:
a.cc: In static member function 'static void Transformation::exeOrder(const std::string&, const StringList&)':
a.cc:29:63: error: no match for 'operator=' (operand types are 'const std::string' {aka 'const std::__cxx11::basic_string<char>'} and 'std::__cxx11::basic_string<char>')
   29 |             src = src.substr(0, a) + order[3] + src.substr(b+1);
      |                                                               ^
In file included from /usr/include/c++/14/string:54,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:2:
/usr/include/c++/14/bits/basic_string.h:817:7: note: candidate: 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>& std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::operator=(const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]' (near match)
  817 |       operator=(const basic_string& __str)
      |       ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:817:7: note:   passing 'const std::string*' {aka 'const std::__cxx11::basic_string<char>*'} as 'this' argument discards qualifiers
/usr/include/c++/14/bits/basic_string.h:858:7: note: candidate: 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>& std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::operator=(std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]' (near match)
  858 |       operator=(basic_string&& __str)
      |       ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:858:7: note:   passing 'const std::string*' {aka 'const std::__cxx11::basic_string<char>*'} as 'this' argument discards qualifiers
/usr/include/c++/14/bits/basic_string.h:941:8: note: candidate: 'template<class _Tp> std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::_If_sv<_Tp, std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&> std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::operator=(const _Tp&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]'
  941 |        operator=(const _Tp& __svt)
      |        ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:941:8: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/14/bits/move.h:37,
                 from /usr/include/c++/14/bits/exception_ptr.h:41,
                 from /usr/include/c++/14/exception:166,
                 from /usr/include/c++/14/ios:41:
/usr/include/c++/14/type_traits: In substitution of 'template<bool _Cond, class _Tp> using std::enable_if_t = typename std::enable_if::type [with bool _Cond = false; _Tp = std::__cxx11::basic_string<char>&]':
/usr/include/c++/14/bits/basic_string.h:149:8:   required by substitution of 'template<class _CharT, class _Traits, class _Alloc> template<class _Tp, class _Res> using std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::_If_sv = std::enable_if_t<((bool)std::__and_<std::is_convertible<const _Tp&, std::basic_string_view<_CharT, _Traits> >, std::__not_<std::is_convertible<const _Tp*, const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>*> >, std::__not_<std::is_convertible<const _Tp&, const _CharT*> > >::value), _Res> [with _Tp = std::__cxx11::basic_string<char>; _Res = std::__cxx11::basic_string<char>&; _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]'
  149 |         using _If_sv = enable_if_t<
      |               ^~~~~~
/usr/include/c++/14/bits/basic_string.h:941:8:   required by substitution of 'template<class _Tp> std::__cxx11::basic_string<char>::_If_sv<_Tp, std::__cxx11::basic_string<char>&> std::__cxx11::basic_string<char>::operator=(const _Tp&) [with _Tp = std::__cxx11::basic_string<char>]'
  941 |        operator=(const _Tp& __svt)
      |        ^~~~~~~~
a.cc:29:63:   required from here
   29 |             src = src.substr(0, a) + order[3] + src.substr(b+1);
      |                                                               ^
/usr/include/c++/14/type_traits:2711:11: error: no type named 'type' in 'struct std::enable_if<false, std::__cxx11::basic_string<char>&>'
 2711 |     using enable_if_t = typename enable_if<_Cond, _Tp>::type;
      |           ^~~~~~~~~~~
/usr/include/c++/14/bits/basic_string.h:828:7: note: candidate: 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>& std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::operator=(const _CharT*) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]'
  828 |       operator=(const _CharT* __s)
      |       ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:828:31: note:   no known conversion for argument 1 from 'std::__cxx11::basic_string<char>' to 'const char*'
  828 |       operator=(const _CharT* __s)
      |                 ~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/basic_string.h:840:7: note: candidate: 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>& std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::operator=(_CharT) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]'
  840 |       operator=(_CharT __c)
      |       ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:840:24: note:   no known conversion for argument 1 from 'std::__cxx11::basic_string<char>' to 'char'
  840 |       operator=(_CharT __c)
      |                 ~~~~~~~^~~
/usr/include/c++/14/bits/basic_string.h:926:7: note: candidate: 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>& std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::operator=(std::initializer_list<_Tp>) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]'
  926 |       operator=(initializer_list<_CharT> __l)
      |       ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:926:42: note:   no known conversion for argument 1 from 'std::__cxx11::basic_string<char>' to 'std::initializer_list<char>'
  926 |       operator=(initializer_list<_CharT> __l)
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~^~~
In file included from /usr/include/c++/14/string:51:
/usr/include/c++/14/bits/stl_algobase.h: In instantiation of 'void std::iter_swap(_ForwardIterator1, _ForwardIterator2) [with _ForwardIterator1 = __gnu_cxx::__normal_iterator<const char*, __cxx11::basic_string<char> >; _ForwardIterator2 = __gnu_cxx::__normal_iterator<const char*, __cxx11::basic_string<char> >]':
/usr/include/c++/14/bits/stl_algo.h:1062:18:   required from 'void std::__reverse(_RandomAccessIterator, _RandomAccessIterator, random_access_iterator_tag) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<const char*, __cxx11::basic_string<char> >]'
 1062 |           std::iter_swap(__first, __last);
      |           ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:1089:21:   required from 'void std::reverse(_BIter, _BIter) [with _BIter = __gnu_cxx::__normal_iterator<const char*, __cxx11::basic_string<char> >]'
 1089 |       std::__reverse(__first, __last, std::__iterator_category(__first));
      |       ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:25:20:   required from here
   25 |             reverse(src.begin() + a, src.begin() + b);
      |             ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:185:11: error: no matching function for call to 'swap(const char&, const char&)'
  185 |       swap(*__a, *__b);
      |       ~~~~^~~~~~~~~~~~
/usr/include/c++/14/bits/exception_ptr.h:229:5: note: candidate: 'void std::__exception_ptr::swap(exception_ptr&, exception_ptr&)'
  229 |     swap(exception_ptr& __lhs, exception_ptr& __rhs)
      |     ^~~~
/usr/include/c++/14/bits/exception_ptr.h:229:25: note:   no known conversion for argument 1 from 'const char' to 'std::__exception_ptr::exception_ptr&'
  229 |     swap(exception_ptr& __lhs, exception_ptr& __rhs)
      |          ~~~~~~~~~~~~~~~^~~~~
/usr/include/c++/14/bits/move.h:226:5: note: candidate: 'template<class _Tp> std::_Require<std::__not_<std::__is_tuple_like<_Tp> >, std::is_move_constructible<_Tp>, std::is_move_assignable<_Tp> > std::swap(_Tp&, _Tp&)'
  226 |     swap(_Tp& __a, _Tp& __b)
      |     ^~~~
/usr/include/c++/14/bits/move.h:226:5: note:   template argument deduction/substitution failed:
/usr/include/c++/14/type_traits: In substitution of 'template<bool _Cond, class _Tp> using std::__enable_if_t = typename std::enable_if::type [with bool _Cond = false; _Tp = void]':
/usr/include/c++/14/type_traits:2323:11:   required by substitution of 'template<class ... _Cond> using std::_Require = std::__enable_if_t<((bool)std::__and_<_Bn>::value)> [with _Cond = {std::__not_<std::__is_tuple_like<const char> >, std::is_move_constructible<const char>, std::is_move_assignable<const char>}]'
 2323 |     using _Require = __enable_if_t<__and_<_Cond...>::value>;
      |           ^~~~~~~~
/usr/include/c++/14/bits/move.h:226:5:   required by substitution of 'template<class _Tp> std::_Require<std::__not_<std::__is_tuple_like<_Tp> >, std::is_move_constructible<_Tp>, std::is_move_assignable<_Tp> > std::swap(_Tp&, _Tp&) [with _Tp = const char]'
  226 |     swap(_Tp& __a, _Tp& __b)
      |     ^~~~
/usr/include/c++/14/bits/stl_algobase.h:185:11:   required from 'void std::iter_swap(_ForwardIterator1, _ForwardIterator2) [with _ForwardIterator1 = __gnu_cxx::__normal_iterator<const char*, __cxx11::basic_string<char> >; _ForwardIterator2 = __gnu_cxx::__normal_iterator<const char*, __cxx11::basic_string<char> >]'
  185 |       swap(*__a, *__b);
      |       ~~~~^~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:1062:18:   required from 'void std::__reverse(_RandomAccessIterator, _RandomAccessIterator, random_access_iterator_tag) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<const char*, __cxx11::basic_string<char> >]'
 1062 |           std::iter_swap(__first, __last);
      |           ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:1089:21:   required from 'void std::reverse(_BIter, _BIter) [with _BIter