The 15th president James Buchanan was unwed I believe. His niece acted as the first lady. Today of course the chances of this happening are almost impossible
Thomas Jefferson was a widower when he was President of the United States, though he was married earlier in life.
Grover Cleveland was a bachelor when elected in 1884. He married Frances Folsom in the Blue Room of the White House in 1886.
http://en.wikipedia.org/wiki/Grover_Cleveland#Marriage_and_children
Sort of landing around your question, three presidents got married while in office. Cleveland, who is mentioned somewhere else in the thread was the only one who had been a bachelor.
Both John Tyler and Woodrow Wilson were widowers who remarried while in office.
There were quite a few widowed Presidents actually. Notably, Andrew Jackson's wife died of a heart attack between his election and inauguration. She was buried in the dress she'd picked out for the inauguration.
OP can you clarify: is this question restricted to the USA, or presidents anywhere?
I'm curious as to what would the husband of a female president would be called. First Gentleman prehaps?