Xcode Cannot Run the Default "Hello World" C++ Program

Hi, I am new to Xcode and C++. I created a helloword project and the main.cpp file is created automatically.

#include <iostream>

int main(int argc, const char * argv[]) {
  // insert code here...
  std::cout << "Hello, World!\n";
  return 0;
}

I tried to run this program by clicking the Run under Product. It said "Compile Successfully" but then I ran into

Thread 1: EXC_BAD_ACCESS (code=2, address=0x7fff23947cb1)

and the program remained on running without termination.

I'm using BigSur (11.2) and I can run the code in command line with

>>> c++ main.cpp
>>> ./a.out
Hello World!

but cannot run this code inside Xcode.

Any idea why this is happening?

Thank you for helping!

Any idea why this is happening?

I have tried what you described using Xcode 12.5 on macOS 11.4. It ran without any problems and I could see in the debug console:

Hello, World!
Program ended with exit code: 0

Thus, there may be some issues with your environment, or macOS 11.2 may have some problems to work with the version of Xcode you are using.

Do you think of anything special with your environment?

Xcode Cannot Run the Default "Hello World" C&#43;&#43; Program
 
 
Q