Help please, I wrote a script in C++ for loading a map file, parsing it with XML, and outputting the objects in the file. The XML parser works great, but it won't open the file. I have it exiting if the file doesn't exist, and the file doesn't load, even though it's in the same folder... any suggestions?

void Map::LoadMap(const std::string& filename) {
	std::ifstream file;

	if(!file.is_open()) {
		std::cout << "Loading the map file " << filename << " failed..." << std::endl;
		return;
	}

	Xml xml;
	std::string s;

	while(!file.eof()) {
		s += file.get();
	}

	xml.Parse(s);
	if(xml.GetRoot()->GetType() != "rpgfile") {
		std::cout << "Loading the map file " << filename << " failed because the file isn't the correct type..." << std::endl;
	}

	std::string version = xml.GetRoot()->GetProperty("stickmin");
	std::map<int, MapPoint*> pointref;

	for(int i = 0; i < xml.GetRoot()->GetNodeChildren(); ++i) {
		Xml::Node* node = xml.GetRoot()->GetChild(i);

		if(node->GetType() == "rock") {
			std::cout << "Rock placed." << std::endl;
		} else if(node->GetType() == "grass") {
			std::cout << "Grass placed." << std::endl;
		}
	}

	file.close();
}
void Map::LoadMap(const std::string& filename) {
	std::ifstream file;
 
	if(!file.is_open()) {

is_open() will _always_ return false, no matter what 'filename' you hand over to this LoadMap function.
Think about what you're missing, how will ifstream 'know' which file to open?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.