我正在用 C++ 制作一个 OpenGL 游戏。与其他语言相比,我在 C++ 方面相当缺乏经验。无论如何,我为一些图像创建了一个带有“基本”目录的字符串流。然后我将此字符串流作为函数参数传递给构造函数。构造函数附加一个图像文件名,然后尝试加载生成的路径。然而...
D:\CodeBlocks Projects\SnakeRoid\bin\Debug\Texts\ <-- before appending the filename
Ship01.tgacks Projects\SnakeRoid\bin\Debug\Texts\ <-- After.
显然不对!结果应该是 D:\CodeBlocks Projects\SnakeRoid\bin\Debug\Texts\Ship01.tga
我的代码的相关部分:
std::stringstream concat;
std::string txtFullPath = "Path here";
...
concat.str(""); //Reset value (because it was changed in ...)
concat << texFullPath; //Restore the base path
PS = new PlayerShip(&TexMan, concat); //Call the constructor
构造函数的代码
PlayerShip::PlayerShip(TextureManager * TexMan, std::stringstream &path)
{
texId = 2;
std::cout << path.str(); //First path above
path << "Ship01.tga";
std::cout << path.str(); //Second - this is the messed up one
//Do more fun stuff
}
任何人都知道为什么它“覆盖”字符串流中已经存在的内容?