standard (C) arrays do not have ANY methods. They are nothing more than an access entry point to raw memory.
Map is a type in c++ and may be confusing to use as a variable name.
you can load an array like this:
int dx = 0;
while (in >> MAP[0][dx++] ) ; //no need for dataholder, it is redundant, read directly into the thing.
if your input file has 2,4,6,8 then
map[0][0] is 2, map[0][1] is 4, and map[0][3] is 8.
I have no idea what your 2-d means so I don't know how you want to control the rows and columns as you load data in.
if the file does not fill the array you can track that dx value to know how many you have and where to insert next if you get more. You must do this yourself.
vectors do not destroy anything unless you code it to do so; you have misused or misunderstood the tool. look at the keyword static if you need one to live longer than its scope. Vectors are superior arrays and should be used unless you have a better reason (your reason indicates a problem with you or your code).
> I dont want use vector beacuse its destroys everthing.
> I can^'t use with vector it destroys the code on Main.cpp
Perhaps it would be better to FIX your broken understanding of the language, rather than regress into the primordial soup of arrays.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
// Not a copy of a map, a reference to the actual map in main
void MapLoader(constchar * fname, vector<int> &Map)
{
ifstream in(fname, ios::in);
int dataholder;
while (in >> dataholder) {
//Add the number to the end of the array
Map.push_back(dataholder);
}
// unnecessary with RAII in.close();
}
int main ( ) {
vector<int> myMap;
mapLoader("file.txt",myMap);
}