Pointer and char

Hi, im trying to create "mass" amount of file, but the code i wrote doesnt work due to "Cant add pointer"

1
2
3
4
5
for (int i = 0; i < 250; i++)
	{
	myMapFile[i].open("Map/" + i + ".jrpmap",std::fstream::binary | std::fstream::out);
	}
}


how do i fix this?

Edit:

someone told me to try this but it doesnt work:

1
2
3
4
5
6
char temp[500];
	for (int i = 0; i < 250; i++)
	{
		scanf(temp, "Map/%d%s", i, ".jrpmap");
		myMapFile[i].open(temp ,std::fstream::binary | std::fstream::out);
	}}
Last edited on
Try using std::string:

1
2
3
4
5
6
7
8
9
10
#include <string>

std::string filename;
for (int i=0; i<250; i++)
{
    filename="Map/";
    filename.append(std::toString((long long)i);
    filename.append(".jrpmap");
    myMapFile[i].open(filename.c_str(), std::fstream::binary | std::fstream::out);
}


The first approach won't work because "Map/" is a pointer (const char *) - it's a data type that gives a memory location where the string "Map/" is stored (same for ".jrpmap"). When you add i to it, what you're actually doing is changing the memory location it stores - which will result in a memory leak.
Topic archived. No new replies allowed.