OK so I've just started trying to figure out how to do it, and there's plenty of tutorials how to get a line from a .txt document, but there's no indication of how to retrieve data from it similar to a db data.
i'm wanting for the Map ID to to go into an array and be stored for further use elsewhere and a map name so the program can then load the tiles into the game, BUT! I cant seem to find out how i would take '1' from the text file sepratly to 'map1'
the txt file will look like so:
1 2 3 4
//Map ID, Map Name
1, map1
2, map2
3, map3
Any hints/tips of code examples (that aren't too confusing for a noob) would be much appreciate.
BUT! I cant seem to find out how i would take '1' from the text file sepratly to 'map1'
Well if you can get a line of your .txt file into a C++ std::string you're probably half-way there.
I'm assuming the ',' is a 'column separator' of some sort, so the way I'd do it is to find the index of that comma, then pull out the substring from the start of the string up to that.
For example:
1 2 3 4 5 6 7 8 9 10 11 12
#include <string>
#include <iostream>
int main()
{
std::string line( "1, map1" );
int comma_pos = line.find( ',' );
// Create a new string that holds first part of 'line' up to but not including ','.
std::string sub( line, 0, comma_pos );
std::cout << "line=" << line << "\n";
std::cout << "sub=" << sub << "\n";
return 0;
} // main
I suppose the next challenge after that is turning this string into an int...