Change augur code to
Code:
ifstream infile("text.txt");
infile >> numrecords_str;
numrecords = atoi(numrecords_str);
Record *records = new Record[numrecords];
// After your done using the memory you allocated release it
delete [] records;
But actually u dont need to allocate dynamic memory
Code:
#include <iostream>
#include <fstream>
#include <conio.h>
#include <string>
using namespace std;
int main(void)
{
string numrecords_str;
ifstream infile("c:\\text.txt");
infile >> numrecords_str;
int numrecords = atoi(numrecords_str.c_str());
int array[numrecords];
for (int j = 0; j < numrecords; j++)
array[j] = j*2+3;
for (int j = 0; j < numrecords; j++)
cout << array[j] << endl;
getch();
return 0;
}
But still I would recommend dynamic memory allocation or i.e std::vector class that augur suggested, insteed of my code. If the array is to large you might encounter a stack overrun(overflow).