J
JML
Hi,
I have some code which parses a text file and creates objects based on
what is in the text file. The code works just fine on Windows, but when
I compile it using XCode on OS X the parsing goes all wrong. Is there
some known differences with file handling on OS X?
My code is quite long, but one of the defect parts looks like this
(sorry about the indentation - I'm new to posting code on a newsgroup):
//Begin adding NPCs, exits and collision boxes
while ( std::getline(filestream, str) ) {
//Look for regular NPC
if (str == "[NPC]") {
std::cout << "Found NPC. \n";
std::string name;
int x, y, w, h, co_x, co_y, co_w, co_h;
filestream >> name >> x >> y >> w >> h >> co_x >> co_y >> co_w >> co_h;
m_NPCList.push_back( CActor( this, name, x, y, w, h, co_x, co_y, co_w,
co_h ) );
//Look for a path
bool foundPath = false;
std::getline(filestream, str); //Finish previous line
std::getline(filestream, str);
if ( str == "[PATH:LOOP]" ) {
std::cout << "Looped path!\n";
foundPath = true; m_NPCList[m_NPCList.size()-1].SetFollowMethod( 0 );
}
if ( foundPath ) {
std::getline(filestream, str);
while ( str != "[END]" ) {
int x, y;
std::string::size_type loc = str.find( " ", 0 );
std::istringstream x_string(str.substr(0, loc));
std::istringstream y_string(str.substr(loc+1, str.length()-1));
x_string >> x;
y_string >> y;
m_NPCList[m_NPCList.size()-1].AddPathNode( CPoint( x, y ) );
std::getline(filestream, str);
}
}
}
}
On Windows the code parses a file with this content just fine:
[NPC]
Batman 100 100 32 32 8 16 16 8
[PATH:LOOP]
100 100
200 100
200 200
100 200
[END]
But on OS X it goes wrong at around here:
std::getline(filestream, str); //Finish previous line
std::getline(filestream, str);
if ( str == "[PATH:LOOP]" ) {
I have some code which parses a text file and creates objects based on
what is in the text file. The code works just fine on Windows, but when
I compile it using XCode on OS X the parsing goes all wrong. Is there
some known differences with file handling on OS X?
My code is quite long, but one of the defect parts looks like this
(sorry about the indentation - I'm new to posting code on a newsgroup):
//Begin adding NPCs, exits and collision boxes
while ( std::getline(filestream, str) ) {
//Look for regular NPC
if (str == "[NPC]") {
std::cout << "Found NPC. \n";
std::string name;
int x, y, w, h, co_x, co_y, co_w, co_h;
filestream >> name >> x >> y >> w >> h >> co_x >> co_y >> co_w >> co_h;
m_NPCList.push_back( CActor( this, name, x, y, w, h, co_x, co_y, co_w,
co_h ) );
//Look for a path
bool foundPath = false;
std::getline(filestream, str); //Finish previous line
std::getline(filestream, str);
if ( str == "[PATH:LOOP]" ) {
std::cout << "Looped path!\n";
foundPath = true; m_NPCList[m_NPCList.size()-1].SetFollowMethod( 0 );
}
if ( foundPath ) {
std::getline(filestream, str);
while ( str != "[END]" ) {
int x, y;
std::string::size_type loc = str.find( " ", 0 );
std::istringstream x_string(str.substr(0, loc));
std::istringstream y_string(str.substr(loc+1, str.length()-1));
x_string >> x;
y_string >> y;
m_NPCList[m_NPCList.size()-1].AddPathNode( CPoint( x, y ) );
std::getline(filestream, str);
}
}
}
}
On Windows the code parses a file with this content just fine:
[NPC]
Batman 100 100 32 32 8 16 16 8
[PATH:LOOP]
100 100
200 100
200 200
100 200
[END]
But on OS X it goes wrong at around here:
std::getline(filestream, str); //Finish previous line
std::getline(filestream, str);
if ( str == "[PATH:LOOP]" ) {