Ok so im using SFML2.0 with visual studios 2008 if that helps at all.. In the process of creating my game I've come into a problem when using string.substr and i cant figure out for the hell of me why this is happening.
In the game I'm creating, like most other games you need to load from a database, simple enough. So I started writing my database reader in my program and created a sample DB for my reader. It opens, checks for the right DB and formatting, finds, and reads the lines and stores them into a dynamic array of strings for me to manipulate.. But when i actually get to the area where my actual data is I cannot get it to find the right line in my code to be able to decifer where the data is on the line..
If that didnt make enough sense let me show you. If within my database i had the line RegionID==1, i cant get my code to find the part of the string which has the "==" in it to seperate the data table with the data.
Within my code here is the segment where it takes one of the lines within the database which has been read, then it checks the string for the "==" and tries to read the data into the game
dataLine is the string with the data being read, break() is just a cout function to help me decifer whats breaking and the variable dataRep is the "==" which is supposed to be being found within the string
for (int cntr = 0; cntr < dataLine.length(); cntr++)
{
Break(8);
std::cout << dataLine.substr(cntr, cntr + 2) << std::endl;
std::cout << cntr << " " << cntr + 2 << std::endl;
if (dataLine.substr(cntr, cntr + 2) == dataRep)
{
if (dataLine.substr(0, cntr) == "Name")
{
//std::cout << dataLine.substr(cnt + 2, dataLine.length()) << std::endl;
player.setName(dataLine.substr(cntr + 2, dataLine.length()));
break;
}
if (dataLine.substr(0, cntr) == "RegID")
{
//std::cout << dataLine.substr(cnt + 2, dataLine.length()) << std::endl;
player.setRegionID(atoi(dataLine.substr(cntr + 2, dataLine.length()).c_str()));
break;
}
if (dataLine.substr(0, cntr) == "RegX")
{
//std::cout << dataLine.substr(cnt + 2, dataLine.length()) << std::endl;
player.setRegionX(atoi(dataLine.substr(cntr + 2, dataLine.length()).c_str()));
break;
}
if (dataLine.substr(0, cntr) == "RegY")
{
//std::cout << dataLine.substr(cnt + 2, dataLine.length()) << std::endl;
player.setRegionY(atoi(dataLine.substr(cntr + 2, dataLine.length()).c_str()));
break;
}
if (dataLine.substr(0, cntr) == "Direction")
{
//std::cout << dataLine.substr(cnt + 2, dataLine.length()) << std::endl;
player.setDirFacing(atoi(dataLine.substr(cntr + 2, dataLine.length()).c_str()));
break;
}
}
}
so as you can see from my code i had the console output what the actual sub string of what was currently being read and also between which two numbers in the code. The actual numbers i printed within the loop are normal but here is what the substr output reads.
if it was reading the line "PlayerName==Steven" it would output "Pl", "lay", "ayer", "yerNa", "erNa", "rNa", and finally "Na" then ignore the rest of the line.
If anyone has experienced this before please help because this bug does not make sense to me at all.