![](/img/trans.png)
[英]Why are good() and is_open() returning true on Mac if a file does not exist?
[英]Can't read text file yet passing is_open and good checks?
嘗試加載文本文件時出現訪問沖突寫入位置錯誤。 在調試時,我注意到我的“ is_open()”和“ good()”都通過了檢查,因為我到達了“ while(std :: getline(myfile,line))。這怎么可能?這真是愚蠢的是,函數可以很好地在自己的項目中運行,但是由於某種原因,我在這里遇到訪問沖突錯誤。
//標題
static bool LoadObj(std::string file, std::vector<GLfloat> &out_vertices, std::vector<GLfloat> &out_normals);
// CPP
bool Resources::LoadObj(std::string file, std::vector<GLfloat> &out_vertices, std::vector<GLfloat> &out_normals)
{
std::string line;
std::ifstream myfile(file);
if (myfile.is_open())
{
if (myfile.good())
{
while (std::getline(myfile, line))
{
if (!strncmp(line.c_str(), "v", 1))
{
std::string dummy;
std::stringstream ss(line);
ss >> dummy;
while (ss >> line)
{
out_vertices.push_back(std::stof(line));
std::cout << line;
}
}
}
}
}
return false;
}
請參見以下問題的答案。 需要包含一個lib並配置編譯器設置。 包括fstream但“找不到ifstream”和“標識符未定義”
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.