Sri Lanka were bowled out early in the morning for 205, with seamer Vernon Philander finishing with 5-45.
Cook put on century partnerships with Dean Elgar (52) and Hashim Amla (48) as Sri Lanka’s bowlers struggled.
Quinton de Kock and Faf du Plessis hit 42 and 41 not out respectively as South Africa closed with a 432-run lead.
Cook and Elgar began South Africa’s reply in positive fashion before a lightning storm delayed play for 90 minutes. They put on 116 before Elgar top-edged a delivery to Angelo Matthew at mid-on.
Amla’s knock lasted 53 deliveries before he became the 10,000th player in Test history to be dismissed lbw when he was trapped in front by Nuwan Pradeep. (Courtesy BBC Sport)