我正在尝试完成图形处理教程并且卡在输入文件上。我的visual studio不接受.txt文件,尽管它在工作目录中并给它完整的路径名(C:/ - >标识符是未定义的)不确定为什么第一行给出问题所以任何帮助理解这一点真的很感激。
std::ifstream openfile(C:/Users/RDT/Documents/Visual Studio 2017/Projects/TDS1/TDS1/Maps1.txt);
sf::Texture tileTexture;
sf::Sprite tiles;
sf::Vector2i map[100][100];
sf::Vector2i loadCounter = sf::Vector2i(0, 0);
if (openfile.is_open())
{
std::string tileLocation;
openfile >> tileLocation;
tileTexture.loadFromFile(tileLocation);
tiles.setTexture(tileTexture);
while (!openfile.eof())
{
std::string str;
openfile >> str;
char x = str[0], y = str[2];
if (!isdigit(x) || !isdigit(y))
map[loadCounter.x][loadCounter.y] = sf::Vector2i(-1, -1);
else
map[loadCounter.x][loadCounter.y] = sf::Vector2i(x-'0', y-'0');
if (openfile.peek() == '\n')
{
loadCounter.x = 0;
loadCounter.y++;
}
else
loadCounter.x++;
}
loadCounter.y++;
}
sf::RenderWindow Window(sf::VideoMode(640, 480, 32), "Loading Maps");
while (Window.isOpen())
{
sf::Event Event;
while (Window.pollEvent(Event))
{
switch (Event.type)
{
case sf::Event::Closed:
Window.close();
break;
}
}
Window.clear();
for (int i = 0; i < loadCounter.x; i++)
{
for (int j = 0; j < loadCounter.x; j++)
{
if (map[i][j].x != -1 && map[i][j].y != -1)
{
tiles.setPosition(i * 32, j * 32);
tiles.setTextureRect(sf::IntRect(map[i][j].x = 32, map[i][j].y = 32, 32, 32));
Window.draw(tiles);
}
}
}
Window.display();
}
}
答案 0 :(得分:0)
除了提供给ng-file-select
构造函数的路径之外,其他所有内容在您的代码中看起来都不错。我将建议一个简单的更改来解决这个问题。问题出在文件路径上。
openfile()