I've have a class function below (using fstream) for my game that I had working on Visual C++ 2008. When I tried to port my app to xcode, I found it compiled, but complained that the directory doesn’t exist.

Believe me, the directory exists. I've checked and rechecked! Basically this class scans a script file and sets values to my game entities.

I use it like this:

CEntity::script( “fuzzybunny.txt” );

I expect it to load the fuzzybunny.txt file, but instead, it logs an error into my log file like this:

ERROR: could not parse script file: data/scripts/fuzzybunny.txt"

Why would it do that? It reads the file fine when compiling under VC 2008? I haven’t made any code changes since I ported it to xcode, this is strait c++, there shouldn’t be anything concerning portability.

This is the function:

bool CEntity::script( std::string talkfile )
{
	std::string file;
	std::string add = "data/scripts/";
	file = add + talkfile;

	std::fstream filescript( file.c_str(), std::ios::in );

	//If the script couldn't be loaded
	if( filescript == NULL )
	{
		Log("\nERROR: could not parse script file: %s\n", file.c_str());
		return false;
	}

	//some things...  What were parsing the file for
	std::string line;
	std::string search;

	//search the file
	while(!filescript.eof())
	{
		std::getline(filescript, line);

		if( "health" == line.substr(0, line.find(' ')) )
		{
			search = line.substr(7, line.size());
			istringstream myStream(search); //convert string to int
			myStream >> health;
		}
	}
	filescript.close();
	return true;
}

Another thing to note, is if I change the beginning of the function to something like this…

bool CEntity::script( std::string talkfile )
{
	std::string file;
	file = "data/scripts/fuzzybunny.txt";

	std::fstream filescript( file.c_str(), std::ios::in );

…etc

Now it seems to load the fuzzybunny.txt script file… Proving that my directory is right, but making me wonder why it didn’t work the other way around? I also get no Log errors when I do this... Anyone have any ideas why it does this?

Recommended Answers

All 3 Replies

I don't do MAC but I see two possibilities.
The data directory is directly off the root directory std::string add = "/data/scripts/"; or The data directory is a subdirectory of the current working directory. std::string add = "./data/scripts/";

When you build and run a project in Xcode, the executable is placed in the build/Debug (or build/Release) folder relative to the project directory.

Member Avatar for iamthwee

CEntity::script( “fuzzybunny.txt” );

That speech mark symbol looks suspect as well.

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.