I wasn't talking about looking at error messages. That's not using a debugger. I meant setting breakpoints and stepping through your program one line at a time and checking the value of map to make sure it's what you expect it to be, so you know exactly where it goes wrong. That's what a debugger does. VS12 can't magically tell when your program starts doing something you didn't expect, so don't expect that sort of error to show up in its logs.
"vector subscript out of range" means exactly what it says: you did something like myVector[1000] when myVector has a size less than 1000. I assume this means there's a bug in your loops, since you seem to be manually reinventing the for loop in SaveMap.
To save you some time, I took the liberty of rewriting your code from the last post a bit to fix several stylistic issues. Haven't tested it but this should be close to what you're after.
#include <SFML/Graphics.hpp>
#include <iostream>
#include <fstream>
#include <cctype>
#include <string>
#include <vector>
#include <sstream>
using namespace sf;
void LoadMap(const std::string& mapFileName, RenderWindow& window);
void SaveMap(const std::string& mapFileName);
std::vector<std::vector<Vector2i>> map;
std::string tileLocation;
int main()
{
RenderWindow window(VideoMode(640, 480, 32), "TileEngine");
LoadMap("Map1.txt", window);
while(window.isOpen())
{
Event event;
while(window.pollEvent(event))
{
switch (event.type)
{
case Event::Closed:
window.close();
break;
}
}
window.clear();
for(int i = 0; i < map.size(); i++)
{
for(int j = 0; j < map[i].size(); j++)
{
if(map[i][j].x != -1 && map[i][j].y != -1)
{
tiles.setPosition(j * 32, i * 32);
tiles.setTextureRect(IntRect(map[i][j].x * 32, map[i][j].y * 32, 32, 32));
window.draw(tiles);
}
}
}
window.display();
}
SaveMap("Map1Copy.txt");
}
void LoadMap(const std::string& mapFileName, RenderWindow& window)
{
std::ifstream openfile(mapFileName);
Texture tileTexture;
Sprite tiles;
std::vector<Vector2i> mapRow;
std::string line;
if(std::getline(openfile, line)) {
tileLocation = line;
tileTexture.loadFromFile(tileLocation);
tiles.setTexture(tileTexture);
} else {
throw std::logic_error("Invalid tilemap file");
}
while(std::getline(openfile, line)) {
int start_pos = 0;
int end_pos;
while(end_pos = line.find('|', start_pos)) {
int slash_pos = line.find('/', start_pos);
std::string x = line.substr(start_pos, slash_pos - start_pos);
std::string y = line.substr(slash_pos - start_pos, end_pos);
mapRow.push_back(Vector2i(stoi(x), stoi(y)));
}
map.push_back(mapRow);
mapRow.clear();
}
}
void SaveMap(const std::string& mapFileName)
{
std::ofstream savefile(mapFileName);
savefile << tileLocation << '\n';
for(std::size_t row = 0; row < map.size(); row++)
{
for(std::size_t col = 0; col < map[row].size(); col++) {
if(col > 0) {
savefile << "|";
}
savefile << map[row][col].x;
savefile << "/";
savefile << map[row][col].y;
}
savefile << "\n";
}
}
Regarding how to store the map, again, I wouldn't worry about it just yet. It would just be distracting or confusing to get into that before all of these more important and more basic issues are sorted out.