sub unknown size... HELP!!!
Sub must be equal to the no. of lines.. (how to do it??)
#include <iostream>
using namespace std;
int limit(int&x) {
cout<<"Number of lines: ";
cin>>x;
return(x);
}
int l;
struct stud_rec
{
int data;
};
int main () {
int i;
limit(l);
stud_rec sub[]; //sub unknown size (need help on this line)
cout<<"\n";
Sub must have an equal size as the no. of lines.. (how to do it??)
#include <iostream>
#include <new>
struct X
{
int data_;
};
int main ()
{
std::size_t size;
std::cout << "Enter Size: ";
std::cin >> size;
// declare a pointer to the struct X
// and dynamically allocate memory
X* pointer = new (std::nothrow) X [ size ];
// exit if the allocation failed
if( !pointer ) return 1;
// now you can access the member of struct by :
pointer[ 0 ].data_ = 100;
std::cout << "\npointer[ 0 ]: " << pointer[ 0 ].data_;
delete[] pointer; // deallocate memory
}