i<3milfs<40
New Member
Hi, I don't know if this is the right sub-forum to ask this, let me know.
Anyway, I need to know how to read in a list of unspecified length from a file, using c++.
The list will look like this (for instance):
1
2
4
7
But it can be any length.
This is what I have, but it doesn't work:
I may be doing it entirely wrong as I just read about dynamic memory and don't have a very good feel for it. Any help would be appreciated.
EDIT: I've come to understand that I can use vectors to do this, solutions using them will also be fine.
Anyway, I need to know how to read in a list of unspecified length from a file, using c++.
The list will look like this (for instance):
1
2
4
7
But it can be any length.
This is what I have, but it doesn't work:
Code:
int main()
{
int i = 0;
int * p;
p= new (nothrow) int[i];
ifstream infile ("input.txt");
while (infile >> p[i])
{
ifstream infile ("input.txt");
infile >> p[i];
cout << p[i];
cout << "\n";
i++;
}
return 0;
}
I may be doing it entirely wrong as I just read about dynamic memory and don't have a very good feel for it. Any help would be appreciated.
EDIT: I've come to understand that I can use vectors to do this, solutions using them will also be fine.
Last edited: