1

I am newbie to Xcode. I try to create a first problem with C++ (image below) and set some breakpoints to test debugging. I get a problem with input in console window. Particularly, whenever I get input line, I type number and there is nothing i can see in console until i change between target output and all output (i.e. if i am on "target output" and type anything, i have to change into "all output" to see the number i typed, vice versa). And there is one more problem: I can delete the number i typed, i.e. if i type 3, it only allow me to add postfix number such as 31 or anything like it. Cannot change the number. Does anyone know this problem? Please help me. Thank a lot.

This is my code

Quang Khải Đàm
  • 555
  • 1
  • 6
  • 21

1 Answers1

1

in the old way you were allocating an empty array you should give its size which is 'n' here

int *a=new int(n);

your old code had some undefined behavior due to the out of bound access you were trying to do accessing without allocating

at the end of your code you should deallocate the dynamic allocated memory like this :

delete[] a;
Spinkoo
  • 2,080
  • 1
  • 7
  • 23
  • 1 `int` should be allocated though, so even though the program is broken, the OP should see something first time round the loop? – trojanfoe Feb 15 '19 at 09:08