To prevent that, as well as iron and carbon, stainless steel contains chromium and nickel. Just like normal steel, stainless steel is hard but it's also resistant to corrosion.

12