I will also investigate vectors, though I do not really have an understanding of the principle you mentioned.
Do you know what an array is? A vector is like an array, but it starts off with size 0 and you can add as many elements to it as you want. It should take you no more than 30 minutes to learn how to use a vector. The notation can look a little scary, but it's really simple. One beginning C++ book actually starts off teaching about vectors instead of arrays.
If you learn about vectors, you should also check out maps. Have you ever wanted to use an array with strings as the index values? Maybe like this:
Code:
myArray[10];
myArray["Betty"] = "245-0012";
myArray["Mike"] = "312-6789";
cout<<myArray["Mike"]<<endl; //"312-6789";
With a map you can do that. Vectors and maps are known as STL 'containers', and the C++ language has all the facilities to use them. Here are some examples:
Code:
//Vectors:
#include<iostream>
#include<vector>
using namespace std;
int main()
{
//Declare a vector(#include <vector>). The type indicated
//between the <> is the type you are allowed to store in
//the vector. It can be a user defined class as well.
vector<int> myNums;
int n1 = 10;
int n2 = 20;
int n3 = 30;
//Add int's to the vector using the push_back() function.
//push_back() adds elements to the end of the vector:
myNums.push_back(n1);
myNums.push_back(n2);
myNums.push_back(n3);
//Display the int's in the vector:
for(int i = 0; i < myNums.size(); ++i)
{
cout<<myNums[i]<<" ";
}
cout<<endl;
//Erase an element in the vector:
myNums.erase(&myNums[0]);
for(int j = 0; j < myNums.size(); ++j)
{
cout<<myNums[j]<<" ";
}
cout<<endl;
return 0;
}
Code:
//Maps
#include<iostream>
#include<map>
#include<string>
using namespace std;
int main()
{
//Declare a map(#include <map>).
//The first type between the <> is the type of the index
//value, and the second type is the type you want to store
//at that index value.
map<string, string> PhoneBook;
PhoneBook["Betty"] = "245-0012";
PhoneBook["Mike"] = "312-6789";
cout<<PhoneBook["Mike"]<<endl<<endl;
//Declare a different map:
map<string, int> myHeadings;
myHeadings["plane1"] = 30;
myHeadings["plane2"] = 45;
//Display headings:
cout<<myHeadings["plane1"]<<endl;
//Get an "iterator"(which is like a pointer) to the
//beginning of the map. You indicate the type of the map
//you are dealing with and then use the word "iterator":
map<string, int>::iterator i = myHeadings.begin();
//Use the pointer to move along the map and display all
//the elements. There's a little twist though: map's
//actually store the index and the element together in a
//struct called a 'pair'. That means the pointer you have is
//actually pointing to a pair struct. In a pair, the
//index is stored in a member variable called 'first' and
//the element is stored in a member variable called 'second':
for(; i != myHeadings.end(); ++i)
{
cout<<"index: "<<i->first<<" element: "<<i->second<<endl;
}
cout<<endl;
return 0;
}
Should I be trying to write this in a DOS window, or WIN32 application?
If you want to do it in Win32, you're going to need to start reading a 1500 page book called Windows Programming(Petzold).