|
-
January 16th, 2011, 01:00 PM
#1
Problem with fstream/sstream
I'm making a tilemap-engine, and I have a code here which should return a valid filename ( number.map, for example 1.map ) for a function which makes me a random test map. This code of mine however seems to make that filename something like 1.mapÍýýýýÝÝÝÝÝÝãÃ8yúî. Also the "writer"-function adds those odd chars in the end of every line. I can't understand what's wrong with these.
char *mapManager::returnFileName(int number) {
std::string a;
std::stringstream ss;
ss << number << ".map";
a = ss.str();
char *b = new char[a.size()];
memcpy(b,a.c_str(),a.size());
return b;
}
void mapManager::createMap(int number) {
char temp[MAP_SIZE];
int temp2;
std: fstream mapFile;
mapFile.open(returnFileName(number));
for (int i=0;i<MAP_SIZE;i++) {
for (int a=0;a<MAP_SIZE;a++) {
temp2 = sf::Randomizer::Random(0, 1);
temp[a] = numberToMapChar(temp2);
}
mapFile << temp << "\n";
}
mapFile.close();
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|