Yes when you cook and melt cheese you kill off the Listeria since the Listeria cannot survive in the hot temperatures that you melt the cheese in.
So if you're worried about the Listeria that could be contained in cheese you can and should melt the cheese and then the cheese will no longer be infected with or contain any listeria and you won't get infected by the listeria.
Just be sure to fully melt the cheese all the way through and when you melt the cheese completely the cheese would get hot enough to kill off bacteria as well as the Listeria.
That's one way of eating cheese while pregnant is you can melt the cheese and eat it on things such as nachos etc and the cheese will be safe to eat while you're pregnant.