Updated C++ code to use R console output