Dynamic array in Stack? So from this link, I saw this:
#include <iostream>
#include <vector>
int main()
{
int x = 0;
std::cin >> x;
std::vector<char> pz(x);
}
But what I want is something like this:
include <iostream>
include <vector>
using namespace std;
int main()
{
long int *p;
long int *another_p;
p = generate_random_vector(); //this is a function that generates a vector
//and I'm assigning this vector to *p
vector<long int>vectorName(n); //size n will be known when I read from a file
//I would like to store the value of vector of *p in vectorName
*another_p = vectorName; //I would like to store the value of vectorName in *another_p
return 0;
}
So any suggestions on doing this?
Here's what I originally did which isn't allowed in C++:
int main()
{
long int *p;
long int *another_p;
long int arrayName[n]; //n can be obtained from reading a file
p = generate_random_vector();
for ( int i = 0; i < n; i++ )
{
arrayName[i] = p[i];
}
for ( int i = 0; i < n; i++ )
{
another_p[i] = arrayName[i];
}
return 0;
}