2

I am using vscode to write c++ programs in macOS. However I find it hard to debug, and the output of the console is always out of format.

My code is like

#include <stdio.h>
#include <iostream>
using namespace std;
int
main()
{
   printf("Hello World\nWelcome to go to C++\n");
   cout << "hello world" << endl;
   return 0;
}

And the output of the console is

=thread-selected,id="1"
@"Hello World\r\n"
@"Welcome to go to C++\r\n"
@"hello world\r\n"

So is there any configuration I forget to set? Or there's another problem?

Please tell me how to fix that.

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621
Lambert
  • 23
  • 1
  • 5
  • `=thread-selected,id="1"` Looks like you're debugging and not simply running the program. – chb Jan 10 '19 at 06:15

1 Answers1

1

This looks like it is correctly formatted, in that the newlines are where they were specified. Although the line endings printed look different.

Perhaps this thread https://github.com/Microsoft/vscode/issues/2957 can help with user configuration settings to set line endings.

Kieran
  • 224
  • 1
  • 6
  • If I set "externalConsole" in launch.json to true, then the print out results looks normal except for those excess log. How to make the output neat and without any excess information when launching through the outer terminal? – Lambert Jan 10 '19 at 06:46
  • already mentioned by chb on his comment, but some of the additional information looks like it is being written by a debugger. If you build your example code and run it directly is there any issue? – Kieran Jan 10 '19 at 07:53
  • It is ok if I run the .out file directly in the terminal. But somehow this way is inconvenient. If as chb said the debugging and running is different, what is the significance of @"hello world/r/n" instead of just print it? – Lambert Jan 11 '19 at 00:45
  • In a way you are ‘just printing it’. Your code sends that data to the iostream and the in-built terminal chooses how to process that stream for display. In this case the terminal is choosing to append an ‘@‘ at the start of each line and display the line end characters (in this case using windows style line endings). It may also be worth noting that the =thread line is what may be being printed by the debugger as well. – Kieran Jan 12 '19 at 05:45
  • This thread may be of use (https://stackoverflow.com/questions/29957456/change-default-terminal-app-in-visual-studio-code-on-mac) to get VSCode to use the terminal app as its output terminal (this seems to be what you would like it to do). But I would also recommend reading about line endings and std::endl to better understand what those additional characters it is printing on the end of the line represent – Kieran Jan 12 '19 at 05:48