In (1), each of the values is specified to occupy enough columns so that there is at least one space separating them. In (2), the values all run together because the fieldwidth specified for each value is just large enough to hold the value. This output obviously is not very readable. It's better to make the fieldwidth larger than the minimum size required so that some space is left between values. In (3), there are extra blanks for readability; in (4), there are not. In (5), the fieldwidth is not large enough for the value in ans, so it automatically expands to make room for all of the digits.
Setting the fieldwidth is a one-time action. It holds only for the very next item to be output. After this output, the fieldwidth resets to 0, meaning "extend the field to exactly as many columns as are needed." In the statement
cout << "Hi" < setw(5) << ans << num;
the fieldwidth resets to 0 after ans is output. As a result, we get the output