How to specify CUDA device number in C++?

The .to() operation should also work in C++ as described here.