I am trying to declare a user determined amount of unique Char Arrays. I would like to know if this is possible, and if so what is the best way to go about it.
My latest attempt:
int userInput;
cin >> userInput;
cin.ignore(1000, 10);
for(int a = 0; a < userInput; a++)
{
char* boxa[25]; // i was hoping it would be box0,box1,box2,box3 ect.
Try making multi-dimensional arrays, which are essentially arrays of arrays. Multi-Dimensional arrays are essentially arrays of arrays. They are declared like so:
int array[3][5] = { 0 };
You can specify however many dimensions you want of course. In this example the array would have three arrays, and each of these three arrays holds five integers. In your case you just need to create a multidimensional char array, right? If your user wants to enter five different strings, then you just make an char array like this:
note that each element of strArray can have different sizes, and you don't have to worry about memory allocation, the class will manage it for you
ref. http://www.cplusplus.com/reference/string/
^^ That works too. I was just sticking with char arrays because thats what you seemed to want to use, but I strongly recommend using std::strings if you can, they're much better than C-Style strings in many ways.
I am doing a block problem. The blocks get moved around and stacked on each other. The problem i had with strings is that i could not figure out how to pull out one char and leave the rest.
Ex:
string x = "12345"
and i just want to pull out the "3" and leave x = "1245"
that is what made me think of using a char array.
I tried to use the Multi-D array but i still have the same problem i can not declare a multi-D array
for instance, int* block = new block[a][b];
in the problem i do not know how many blocks i will have to manipulate.
Thank you both for the speedy help i really appreciate it. =D
Well you can try using STL and the standard C++ library for that e.g
1 2 3 4 5 6
std::vector<std::string> v;
v.push_back("Ada");
v.push_back("Smalltalk");
v[1].erase(v[1].begin()+4); // removes the second 'l'
another ref. http://www.cplusplus.com/reference/stl/
edit: note that your 'array' does not need to know its size at compile time
edit2: master roshi's explanation is more detailed :s