c++ string数组动态创建

在牛客在线编程测试中,有人的代码可以直接动态创建string数组

   #include <iostream>
    using namespace std;
    ......
    cin>>n;
    string str[n];

然而我的VS并不能通过这样的编码方式,为什么他这样可以呢?
图片说明

#include<iostream>
using namespace std;
int main()
{
    int n;
    cin >> n;
    string* str = new string[n];
    delete []str;
    system("pause");
}

你看这样是否满足你的要求

VS是不能通过编译的,源代码应该是用g++编译的

标准不一样,目前c++11才能这样做

在一些标准中,C++不能用变量来开辟数组的大小

不同编译器厂商实现不一样,gcc和clang可以用实现动态数组,而Visual C++报错。