Why does the terminal show “^[[A” “^[[B” “^[[C” “^[[D” when pressing the arrow keys in macos apple silicon m1 for c++?

  apple-m1, apple-silicon, c++, macos, python

I have refered previous questions but none of those helped. Issue is similar as mentioned here: Why does the terminal show "^[[A" "^[[B" "^[[C" "^[[D" when pressing the arrow keys in Ubuntu?

Executing g++(gcc11) and running it. Cannot move cursor using arrows.

Interestingly, while taking input in python does not have this issue.

Able to move cursor in Python3 input()

I have tried various things including using "bash" shell (3.2), using iTerm2 instead, running macos 11.4 in safe mode. Terminal app’s key bindings are as default settings. None of the mentioned helped.

  • How can this be avoided?

Edit:
C++ Code screenshot added. C++ Code

Source: Windows Questions C++

LEAVE A COMMENT