nullptr problems

This is a code provided at www.cplusplus.com/doc/tutorial/dynamic/. The provided code doesn't work on my computer. I am using Code-Blocks and Microsoft Visual C++ 6.0, and when I change "nullptr" to zero, it works. Is there any problem in the program? Am I missing something?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// rememb-o-matic
#include <iostream>
#include <new>
using namespace std;

int main ()
{
  int i,n;
  int * p;
  cout << "How many numbers would you like to type? ";
  cin >> i;
  p= new (nothrow) int[i];
  if (p == nullptr)
    cout << "Error: memory could not be allocated";
  else
  {
    for (n=0; n<i; n++)
    {
      cout << "Enter number: ";
      cin >> p[n];
    }
    cout << "You have entered: ";
    for (n=0; n<i; n++)
      cout << p[n] << ", ";
    delete[] p;
  }
  return 0;
}
Last edited on
Is there any problem in the program? Am I missing something?

Yes. Microsoft Visual C++ 6.0 was released in 1998. The use of nullptr requires C++11 support.

You might want to upgrade to a more recent version of the compiler.
Thank you very much.
Topic archived. No new replies allowed.