Language: C++

#include <iostream>
#include <string>
#include <map>
#include <algorithm>
#include <cctype>
using namespace std;

typedef string::const_iterator State;
int n;
string str;

int factor(const State &begin);
int number(const State &begin);
int term(const State &begin);
int expressin(const State &begin);

int factor(const State &begin)
{
	int ret;
	if (*begin == '(')
	{
		begin++;
		ret = expressin(begin);
		begin++;
	}
	else
	{
		ret = number(begin);
	}
	return ret;
}

int number(const State &begin)
{
	int ret = 0;
	while (isdigit(*begin))
	{
		ret *= 10;
		ret += *begin - '0';
		begin++;
	}
	return ret;
}

int term(const State &begin)
{
	int ret = factor(begin);
	while (true)
	{
		if (*begin == '*')
		{
			begin++;
			ret *= factor(begin);
		}
		else if (*begin == '/')
		{
			begin++;
			ret /= factor(begin);
		}
		else
		{
			break;
		}
	}

	return ret;
}

int expressin(const State &begin)
{
	int ret = term(begin);
	while (true)
	{
		if (*begin == '+')
		{
			begin++;
			ret += term(begin);
		}
		else if (*begin == '-')
		{
			begin++;
			ret -= term(begin);
		}
		else
		{
			break;
		}
	}

	return ret;
}


int main()
{
	cin >> n;
	while (n--)
	{
		cin >> str;
		cout << expressin(str.begin()) << endl;
	}

	return 0;
}

Compiler output:
a.cc: In function 'int factor(const State&)':
a.cc:22:22: error: passing 'const State' {aka 'const std::__cxx11::basic_string<char>::const_iterator'} as 'this' argument discards qualifiers [-fpermissive]
   22 |                 begin++;
      |                      ^~
In file included from /usr/include/c++/14/string:48,
                 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:1:
/usr/include/c++/14/bits/stl_iterator.h:1108:7: note:   in call to '__gnu_cxx::__normal_iterator<_Iterator, _Container> __gnu_cxx::__normal_iterator<_Iterator, _Container>::operator++(int) [with _Iterator = const char*; _Container = std::__cxx11::basic_string<char>]'
 1108 |       operator++(int) _GLIBCXX_NOEXCEPT
      |       ^~~~~~~~
a.cc:24:22: error: passing 'const State' {aka 'const std::__cxx11::basic_string<char>::const_iterator'} as 'this' argument discards qualifiers [-fpermissive]
   24 |                 begin++;
      |                      ^~
/usr/include/c++/14/bits/stl_iterator.h:1108:7: note:   in call to '__gnu_cxx::__normal_iterator<_Iterator, _Container> __gnu_cxx::__normal_iterator<_Iterator, _Container>::operator++(int) [with _Iterator = const char*; _Container = std::__cxx11::basic_string<char>]'
 1108 |       operator++(int) _GLIBCXX_NOEXCEPT
      |       ^~~~~~~~
a.cc: In function 'int number(const State&)':
a.cc:40:22: error: passing 'const State' {aka 'const std::__cxx11::basic_string<char>::const_iterator'} as 'this' argument discards qualifiers [-fpermissive]
   40 |                 begin++;
      |                      ^~
/usr/include/c++/14/bits/stl_iterator.h:1108:7: note:   in call to '__gnu_cxx::__normal_iterator<_Iterator, _Container> __gnu_cxx::__normal_iterator<_Iterator, _Container>::operator++(int) [with _Iterator = const char*; _Container = std::__cxx11::basic_string<char>]'
 1108 |       operator++(int) _GLIBCXX_NOEXCEPT
      |       ^~~~~~~~
a.cc: In function 'int term(const State&)':
a.cc:52:30: error: passing 'const State' {aka 'const std::__cxx11::basic_string<char>::const_iterator'} as 'this' argument discards qualifiers [-fpermissive]
   52 |                         begin++;
      |                              ^~
/usr/include/c++/14/bits/stl_iterator.h:1108:7: note:   in call to '__gnu_cxx::__normal_iterator<_Iterator, _Container> __gnu_cxx::__normal_iterator<_Iterator, _Container>::operator++(int) [with _Iterator = const char*; _Container = std::__cxx11::basic_string<char>]'
 1108 |       operator++(int) _GLIBCXX_NOEXCEPT
      |       ^~~~~~~~
a.cc:57:30: error: passing 'const State' {aka 'const std::__cxx11::basic_string<char>::const_iterator'} as 'this' argument discards qualifiers [-fpermissive]
   57 |                         begin++;
      |                              ^~
/usr/include/c++/14/bits/stl_iterator.h:1108:7: note:   in call to '__gnu_cxx::__normal_iterator<_Iterator, _Container> __gnu_cxx::__normal_iterator<_Iterator, _Container>::operator++(int) [with _Iterator = const char*; _Container = std::__cxx11::basic_string<char>]'
 1108 |       operator++(int) _GLIBCXX_NOEXCEPT
      |       ^~~~~~~~
a.cc: In function 'int expressin(const State&)':
a.cc:76:30: error: passing 'const State' {aka 'const std::__cxx11::basic_string<char>::const_iterator'} as 'this' argument discards qualifiers [-fpermissive]
   76 |                         begin++;
      |                              ^~
/usr/include/c++/14/bits/stl_iterator.h:1108:7: note:   in call to '__gnu_cxx::__normal_iterator<_Iterator, _Container> __gnu_cxx::__normal_iterator<_Iterator, _Container>::operator++(int) [with _Iterator = const char*; _Container = std::__cxx11::basic_string<char>]'
 1108 |       operator++(int) _GLIBCXX_NOEXCEPT
      |       ^~~~~~~~
a.cc:81:30: error: passing 'const State' {aka 'const std::__cxx11::basic_string<char>::const_iterator'} as 'this' argument discards qualifiers [-fpermissive]
   81 |                         begin++;
      |                              ^~
/usr/include/c++/14/bits/stl_iterator.h:1108:7: note:   in call to '__gnu_cxx::__normal_iterator<_Iterator, _Container> __gnu_cxx::__normal_iterator<_Iterator, _Container>::operator++(int) [with _Iterator = const char*; _Container = std::__cxx11::basic_string<char>]'
 1108 |       operator++(int) _GLIBCXX_NOEXCEPT
      |       ^~~~~~~~