From: Alan T. <ala...@3n...> - 2001-04-07 01:50:47
|
Nathan, Can you use a vector or other container that is easily = and safely extended? Perhaps an array is a bad choice for what you`re = trying to do. See = http://www.icce.rug.nl/docs/cplusplus/cplusplus08.html#l112 for vectors = and http://www.icce.rug.nl/docs/cplusplus/cplusplus08.html#l109 for C++ = abstract containers. Below is an example of how to use the vector container (for = a vector of strings). Alan #include <string> #include <iostream> #include <fstream> #include <vector> using namespace std; int main() { vector<string> v; ifstream in ("Fillvector.cpp"); string line; while (getline(in, line)) v.push_back(line); // Add line to the end // Add line numbers: for (int i=3D0; i < v.size(); i++) cout << i << ": " << v[i] << endl; =20 system("PAUSE"); return 0; } Message: 2 From: "Nathan Smith" <str...@ho...> To: "Dev C++" <dev...@li...> Date: Fri, 6 Apr 2001 14:09:46 +1000 Subject: [Dev-C++] Extending an array Reply-To: dev...@li... Is there a way at runtime, after an array has been populated to extend = it? Like I have char stuff[40][17] and I want to extend it to = stuff[xxxx][17]? |