Why don't superconductors, which have zero electrical resistance, violate the second law of thermodynamics? There are bunch of questions on here asking whether superconductors really have exactly zero resistance and answers saying they do.  My question is how this doesn't violate the second law of thermodynamics, which, if I understand correctly, implies that there will always be some energy lost as heat to any system that converts energy to a useful form.  Or, in other words, it's fundamentally impossible to convert energy to work with 100% efficiency.
But, if there's no resistance when a current flows through a superconductor, doesn't that mean there's no energy lost as heat?  That would seem to imply we're adding energy to a system (by getting a curent going) without increasing the entropy, which should be impossible — more energy means an increased number of possible microstates of the system, which means the ratio of micro to macro states should increase and hence increase the entropy.  But I don't see how that can be the case if there's no resistance.
Obviously there's something wrong with my reasoning here, but what?  From answers I've seen to similar questions, people said that the energy needed to cool the system down accounts for the second law, but if that were it then surely room temperature superconductors should be impossible even in principle.  and yet, reputable scientists have been looking for them anyway.  So what am I missing here?  Is there some other mechanism through which energy gets converted to heat?  And if that's the case, why are superconductors even useful, if there's still energy lost anyway?
 A: While I agree with the other answers regarding work required to initiate current, and no work done by the current, let me add another perspective.

But, if there's no resistance when a current flows through a superconductor, doesn't that mean there's no energy lost as heat? That would seem to imply we're adding energy to a system (by getting a current going) without increasing the entropy, which should be impossible — more energy means an increased number of possible microstates of the system, which means the ratio of micro to macro states should increase and hence increase the entropy. But I don't see how that can be the case if there's no resistance.

(emphasis mine)
What is implicit in the argument about the number of microstates, is that there are mechanism, which allows transitions between these microstates. In particular, in a normal conductor these would be transmission of energy to phonons and other excitations, whereby the energy from the current is diffusing away. Usual thermodynamic arguments imply that such interactions exist, even though they can be neglected, and the the system visits all possible configurations during its time evolution (known as ergodicity.)
These arguments do break when there is no relaxation mechanism (as in superconductors) - there is minimum energy required for dissipation to occur, which is reached only when we reach critical current density (and as the dissipation occurs, the superconductivity is destroyed.)
Not unrelated case where the thermodynamic arguments fail is when the relaxation mechanisms are too slow for reaching equilibrium within the reasonable time (which is no bigger than the time of the existence of the Universe, but in practice is shorter than the lifetime of a scientist performing the experiment.) This is how phase transitions occur, as, e.g., permanent magnetization of a magnet. Phil Anderson has given a valuable discussion of this point in his More is Different article.
A: 
But, if there's no resistance when a current flows through a superconductor, doesn't that mean there's no energy lost as heat? That would seem to imply we're adding energy to a system (by getting a curent going) without increasing the entropy, which should be impossible

Second principle only applies to a closed system, that is a system that has no exchange with anything outside of itself.
For example if I use a heat pump to suck heat out of my house in the summer, entropy inside my house will reduce. But the house is not a closed system, it is an open system that exchanges energy with the outside. If we widen the system to include the heat pump and outside environment, it is still an open system but already we can see that entropy is decreasing much less due to the losses in the heat pump. If we include the electrical powerplant and the grid, there are even more losses and increase of entropy to produce the required energy. To have a real closed system you'd have to include the entire universe, and indeed as the second law says there will always be an increase in global entropy even though there is a decrease in local entropy.
In the case of your superconductive magnet, second principle does not apply because it is an open system. Its entropy can both increase and decrease depending on energy exchange with the outside.
If you widen the field of view to include the device that will produce the energy that you will store inside the superconductive magnet's field, now it begins to look more like a closed system, and the second principle begins to apply. Indeed if you use a coal fired power plant powering a steam turbine alternator to create current to power your magnet, global entropy will increase.
It is somewhat possible to store energy into something without an increase in entropy: think about the potential energy of gravity: if you raise a weight in a gravity field there is no loss, you can store potential energy without thermal losses. However this is an open system, and you cannot produce the energy to do this work without a global increase in entropy.
In the case of the magnet, charging its magnetic field will emit electromagnetic waves which will propagate at the speed of light into the universe. So even in this case, even if it is superconducting, even if you assume an ideal generator, some of the energy you put into it will always escape and is not recoverable.
Note there are reversible processes, for example think about a simple chemical reaction at equilibrium, like an acid in water: CH3OOH + H2O <-> CH3OO- + H3O+
If the reaction is at equilibrium, there will always be some acid molecules giving H+ to water while some other acid molecules steal H+ from H3O+. This is reversible and it produces no work.
A: You correctly wrote:

there will always be some energy lost as heat to any system that converts energy to a useful form. Or in other words, it's fundamentally impossible to convert energy to work with 100% efficiency.

Now, a steady current in a superconductor does not do any work. No work, no contradiction with the principles of thermodynamics.
Of course, to establish the circulating current, one has to do some work. For example, some normal current must pass through a solenoid to switch on or off a magnetic field. But that is external work done on the system to start the stationary current.
A: Superconductors only have zero electrical resistance to direct (dc) current flow. To change the current in a superconductor requires work to be done through the input of energy, which is lost as heat.
This observation may help to address some of your conceptual concerns. As to the question of why a dc current flow through a superconductor doesn't violate the second law of thermodynamics, no work is done. More energy doesn't imply more possible microstates of the system since all superconducting charge carriers occupy a single quantum state -- the energy is not distributed between them. The question is then analogous to that of why electrons orbiting an atom do not violate thermodynamics (and the classical vs quantum mechanical analogies are similarly parallel in that superelectrons no more flow along wires than regular ones circulate atoms -- rather, both are described by a wavefunction).
The energy needed to cool the system is irrelevant for the reason you give as well as the fact that cold places exist.
And finally, superconductors are useful in spite of the energy loss since that energy can still be relatively small, many applications of interest operate at (or close to) dc, and the current density achievable can still be very high.
A: you can model the current flowing in a superconducting loop exactly like the rotation of a flywheel, where the bearings have zero friction.
It took work to set the flywheel in rotation and, once rotating in the absence of friction, the flywheel will keep rotating forever.
Stopping the flywheel from rotating will require the expenditure of work.
A: The second law of thermodynamics only says that no process can decrease the entropy of the universe (i.e. destroy entropy). An equivalent view is that no process can create exergy. From a field perspective, the divergence of entropy is always positive.
While rough reasoning like you are stating are ways to start, actual candidates for a violation of the second law must amount to the destruction of entropy or creation of exergy. If you believe you have found a candidate for a violation, you should be able to state where that happened (the entropy destruction). I'm not just hand waving here, a second law violation should accompany a theoretical type two perpetual motion machine.
To my understanding, current flowing indefinitely in a superconducting wire is not destroying any entropy. This is not even considering the fact that the "superconductor" may still have a finite resistance, and so slowly generate heat and come to a zero current state.
Idealized processes, like true superconductors, frictionless bearings for flywheels, resistanceless batteries, engines and refrigerators that transfer heat at zero temperature differential, and so on, are not violations of the second law. They are the boundary between possible and impossible processes. In effect, all real processes are irreversible and "reversible" processes are the boundary between real, irreversible processes and impossible processes that violate the second law. I am using the term "boundary" pretty literally here, in reference to phase space. There are also all sorts of processes in phase space that violate the first law, but that those are impossible is not too controversial for people to understand.
To answer your example, a single material conductor that can be at thermal equilibrium with its surroundings and start a current flowing in itself by becoming colder than its surroundings is a second law violation. You can see how this is vastly different than a superconductor. The way I said this is important, because thermocouples are not second law violations. Also note that this example is a theoretical type two perpetual motion machine. Such a conductor could use the energy of the surroundings to run a motor forever in a closed system. For obvious reasons, thermocouple type devices cannot be used to construct a PPM.
Note that rotating bodies in space "rotate forever" and this is not a second law violation (use this example if you don't like the frictionless flywheel someone said elsewhere). A remote astronomical body will rotate forever, no mechanical energy is created by that and there is no second law violation. In reality, it may not rotate forever due to gravity waves, etc.
