Re: Uploading Vector To File
Quote:
Originally posted by lifeofjdm
I am now using Dev-C++ 4, and am trying to upload my vector elements using the infile as I did with VC4, but I do realize that they are not the same.
Code:
username.reserve(100);
//....
infile >> username[index]; // illegal operation
The vector is empty, and you are trying to access a non-existing element. You are lucky it doesn't crash in VC 4.0.
No, reserve() does not add elements to the vector, resize() does.
The reserve function only gives the vector more memory up front so that operations such as push_back() are more efficient. The reserve() does not actually give you more elements.
Code:
username.resize(100);
//....
infile >> username[index]; // OK if index is between 0 and 99, inclusive
Regards,
Paul McKenzie