I've been stuck on several problems. I'm still an inexperienced programmer of C++, and I've recently learnt arrays, pointers and dynamic memory.
There's two things that I'm having trouble with:
1. Turning an integer into a string.
2. Reading the amount of lines in a text file, and making an array accordingly (i.e. to read a list of weapon names into a game from an external file).
I'm sure there'll be a simple solution that I've probably missed, so I'm sorry about the simplicity of it.
int my_array[SIZE];
//assume there is only SIZE ints in the file
for(unsignedint i = 0; i < SIZE; ++i) {
//read an int
my_array[i] = the_int;
}
You can just do something like this:
1 2 3 4 5 6
std::vector<int> my_vector;
while(/*there are still ints in the file*/) {
//read an int
my_vector.push_back(the_int); //adds it to the vector
//no need to care about the size or anything
}