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.
Asked
Active
Viewed 69 times
1
-
Is [this question](https://stackoverflow.com/questions/1780600/xcode-entering-user-input-when-debugging) related? – trojanfoe Feb 15 '19 at 08:45
-
post the code directly here please – Spinkoo Feb 15 '19 at 08:51
1 Answers
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