You heard wrong.
There are very few proven links between diet (any diet, any food) and any of the 200+ types of cancer. And (like 'meat causes cancer'), 'vegetarianism/veganism prevents/treats/cures cancer' isn't one of those very few proven links.
After almost a lifetime as a vegetarian and almost nine years as a vegan I was diagnosed with stage 3 grade 3 breast cancer (that's advanced and aggressive).
Through cancer support networks, I met six other vegans with cancer (one a lifelong vegan), several dozen vegetarians with cancer, and several hundred meat-eaters with cancer. This pretty much reflects the percentages of each group in society in general; fewer vegans than non-vegans are diagnosed with cancer simply because fewer people are vegan, simple as that.
A diet high in red and processed meat is known to be a major risk factor for colorectal cancers; such a diet is also thought to be a possible risk factor for stomach cancer; and a diet high in meat and fat is thought to be a possible risk factor for pancreatic cancer.
There have been a couple of studies whose findings suggest that a diet high in dairy might be a possible risk factor for prostate cancer.
That's it for the known or suspected links between meat and dairy and the 200+ types of cancer. The fact is that nobody knows what causes cancer, and by the same token nobody can tell you how to prevent it. Cancer is a largely random disease.
Linda McCartney had breast cancer. Neither meat nor dairy are established as risk factors for breast cancer. The biggest risk factor for breast cancer is being a female, the second biggest is being over 50. One in eight women will develop breast cancer over a lifetime of around 80 years, and 80% of those women will be over 50. Linda McCartney was in her 50s when she was diagnosed with cancer.