Enter a number: 1234
1234
1234
1234
1234
1234
-2147483648
That last line of output looks rather suspiciously wrong, along with most of the other lines of output.
You are missing a number of headers for the functionality you use. Not every compiler implementation implicitly includes other headers in commonly used headers such as <iostream>. <string> is one that MSVC++ needs to be explicitly included if you want to use C++ strings. No include and C++ string code will not compile.
<algorithm> for std::max, <cstdlib> for std::atoi are also recommended.
#include <iostream>
#include <algorithm>
#include <string>
#include <limits>
int main() {
int m;
std::cout << "Enter a number containing at least one digit 5: ";
std::cin >> m;
constauto s { std::to_string(m) };
auto nummax { std::numeric_limits<int>::min()};
for (size_t j {}; j < s.size(); ++j)
if (s[j] == '5')
nummax = std::max(nummax, std::stoi(s.substr(0, j) + s.substr(j + 1)));
std::cout << nummax << '\n';
}