William R. Cox was born in Scotland Neck, Halifax County, North Carolina, to an aristocratic family that lived in North Carolina since the colonial days. His father died when Cox was only four years old. His mother and his siblings subsequently moved to Nashville, Tennessee, where he was raised and educated. He graduated from Tolbert Fanning's Franklin College in Franklin, Tennessee and studied at the Lebanon Law School. After passing his bar exam, Cox formed a partnership with a prominent Nashville attorney, and his practice flourished. In 1857, Cox ceased his practice, married, moved back to North Carolina, and owned a plantation in Edgecombe County. Two years later, he moved to Raleigh and entered politics, running as a Democrat for the state legislature. He was narrowly defeated, losing a hard-fought election by just thirteen votes in his district.
With North Carolina's secession and the outbreak of the Civil War in early 1861, Cox raised and outfitted the "Ellis Artillery Company". He soon afterwards raised an infantry company and was appointed as the major of the 2nd North Carolina Infantry Regiment by Governor Ellis. He fought in the Battle of Antietam, and was given a promotion to lieutenant colonel, as he and the officer previously holding that rank were promoted with the death of the regiment's first colonel, Charles C. Tew, in that battle. Not long afterwards, the new colonel resigned and Cox assumed command of the veteran regiment. He was formally commissioned as the colonel of the 2nd North Carolina in March 1863. In May of that year, Cox was wounded three times in the fighting at the Battle of Chancellorsville. Despite his painful wounds, he stayed in command until late in the fighting when exhaustion forced him to retire to a field hospital to be treated. Missing the Gettysburg Campaign due to his injuries, Cox did not return to the field until the fall of 1863. While temporarily in command of Ramseur's Brigade because the general was on leave to get married, Cox was wounded in the face and right shoulder early in the battle of Kelly's Ford on November 7, 1863. Shipped to the hospital in Richmond, the wound resulted in a 40-day furlough to recuperate. He fought with distinction at the battles of the Wilderness and Spotsylvania Court House, being personally commended by General Robert E. Lee for bravery in fighting on May 12. Afterwards he was assigned command of a brigade of North Carolina infantry, despite being junior in rank to other colonels in the brigade. He led his troops at the Battle of Cold Harbor and then accompanied the Army of the Valley under Maj. Gen. Jubal Early in the Shenandoah Valley. At the Battle of Monocacy, Cox's brigade played a prominent role in the day-long fighting. Returning to the Army of Northern Virginia, Cox served in the trench defenses during the Siege of Petersburg, including the counterattack of Confederate forces on the Union's Fort Stedman. Promoted to brigadier general, Cox led a brigde during the final year of the war, including the Appomattox Campaign. He surrendered his men to the Federal army at Appomattox Court House in April 1865 and returned home. During the course of the war, he survived a total of eleven wounds.
Postbellum career
After the war, Cox resumed his legal practice in Raleigh and became President of the Chatham Railroad. He spent six years as the solicitor for metropolitan Raleigh, and was chairman of the North Carolina Democratic Party from 1874 through 1877. In January 1877, he became Circuit Superior Court Judge of the Sixth Judicial District. He endured the death of his wife in 1880. He resigned his judgeship when he was elected to the United States Congress, serving for six years as a representative from North Carolina. In the House, he championed civil service reform, a stance which alienated some prominent Democrats, leading to him losing the party nomination for re-election in 1886. He remarried and retired to his plantation in Edgecombe County, but was appointed Secretary of the U.S. Senate to replace former Union army general Anson G. McCook in 1893. He served until the turn of the century, when he again retired, this time for good, to his plantation. At the time of his death in 1919, he was one of the last surviving generals of the Confederate army. He is buried in Raleigh's Historic Oakwood Cemetery.