Use a level-generator program to create the level you want.
Then save it to a level file.
Then include the level file's data in your code (or in your program's assets folder).
Presumably your code has a function to read a level from file/stream, right?
I currently have a platformer game with hardcoded platforms in specific places.
And how you currently storing those hardcoded platforms?
Edit: For example, you might have a list/array of platforms or something like that. But with load-from-a-file changes, you can still have this list of platforms, but you should set the values of those platforms based off the values in a file.
Note that data containers like std::vector are resizable at run-time, unlike C arrays.
Okay good, so from there, you can hopefully imagine doing something like this:
1 2 3 4 5 6 7 8 9 10
std::vector<Platform> platforms;
std::ifstream fin("level.txt");
sf::Vector2f size;
sf::Vector2f position;
while (fin >> size.x >> size.y >> position.x >> position.y) // extract information from file
{
platforms.push_back(Platform(nullptr, size, position));
}
And your level.txt might look like this:
900.0 25.0 450.0 890.0
123.0 456.0 789.0 1000.0
(two platforms)
That's one way to do it, and it would be a good start. But it sounds like you want to store the entire map in a file in a different way, where you have a tile-based map?
If that's the case, then you'd loop through your file in a different way.
You could do something like this:
level_grid.txt
7 3
0 0 0 0 0 0 1
0 1 1 0 1 1 1
1 1 0 0 0 0 0
I put the width and height of the map in there for easier parsing (imo).