They knew most of the cutting-edge mathematics of their times, by studying with the people who invented it, or by voraciously reading all they could put their hands on. They maintained extensive contact with colleagues, be it by meeting in some Academy or other or just by mail. Not that far from how today's prominent mathematicians came to know what they know. Technology has made it all much easier, and there are more people involved, in ever more specialized branches.
We remember a few names from Euler's day (some almost only because they threw a intriguing conjecture around, which still hasn't been resolved), but there were a lot more mathematicians around then. Just like today, in any field there are a few superstars, a lot of known people, and many, many "also ran"s.
Note: What they did read is mostly moot, e.g. Euler studied under one of the Bernoullis; l'Hôpital had recently finished the first calculus book, and Euler himself wrote precalculus/calculus textbooks that became classics.
Besides, the techniques and notation (pre-Euler, at least) are completely alien (much of our modern notation was introduced by Euler). For some ideas on how they worked, check e.g. William Dunham's "Euler: The master of us all" (AMS, 1999), "Journey through Genius" (Penguin, 1990) or "The Mathematical Universe" (Wiley, 1997), particularly interesting is Leibnitz' proof of what we call integration by parts. Ed Sandifer's "How Euler did it" was a monthly column discussing some of Euler's work, somewhat updating notation (sometimes).
I've no such resources handy for Lagrange or Gauß, sorry.