Vietnam was not winnable
unless the U.S. was prepared to nuke North Vietnam and maybe start a war with China, which was providing aid to NV. In hindsight we should have never gotten involved in Vietnam, of course---we should have learned from the French experience--but those were the days of the "domino theory" and the anti-communist fervor of John Foster Dulles. We eventually saw the writing on the wall and just got out.
We didn't lose Afghanistan or Iraq--we exposed them to how modern, sane, advanced nations operate and eventually decided to leave. The Bush
administration lied to Americans to justify our invasion of Iraq, but roughly 20 years after the ouster of Saddam Hussein Iraq is arguably in a better place. And it's democratic. Our short-term effort at nation-building was rocky and violent and yet seems to have significantly helped that country, though of course there are still many problems. We still have some military bases in Iraq.
Read this story about Iraq and its current president from a month ago.
Iraqi president says country now peaceful, life is returning
We entered Afghanistan to get rid of a terrorist hub, did so, and then spent, what, 20 years trying to turn a medieval mudbank into some rudimentary semblance of country. We didn't succeed but weren't going to succeed unless we were prepared to stay in Afghanistan for at least 50 years. We're talking about a culture straight out of the middle ages. I think we should have stayed, FYI. The Taliban is back running the place, girls and women are again suffering under an oppressive Islamic government--but I think our 20-year presence will yet have a positive influence on that place and the Taliban.