I am trying to store a value from a
vector<vector<string>> data;
into a const char* variable - declared in the .h file - in this way:
heightmapName = data[0][1].c_str();
When I debug the program I notice that the variable heightmapName
return this
heightmapName 0xcdcdcdcd <Error reading characters of string.> const char *
However, if I declare a new const char*
and initialize it like this:
const char* what = data[0][1].c_str();
heightmapName = data[0][1].c_str();
what
variable store the data just fine, while heightmapName
doesn't.
This is the function:
void Configuration::fileParser(string fileName)
{
vector<vector<string>> data;
string line;
string delimiter = " ";
ifstream ss(fileName);
if (ss)
{
while (getline(ss, line))
{
vector<string> dataLine;
string token = line.substr(0, line.find(delimiter));
string value = line.substr(line.find(delimiter) +1);
dataLine.push_back(token);
dataLine.push_back(value);
data.push_back(dataLine);
}
ss.close();
}
//storeData(data);
const char* ahah = data[0][1].c_str();
heightmapName = data[0][1].c_str();
}
Why is this happening? and how can I solve this?
ps. I am using visual studio 2017