Ulysses S. Grant (born Hiram Ulysses Grant; April 27, 1822 – July 23, 1885) was the 18th President of the United States (1869–1877) following his highly successful role as a war general in the second half of the Civil War .