c++ - Assign a string from an iterator -



c++ - Assign a string from an iterator -

here problem have , have vector of filenames , want check if end .jpg or .png made code iterators , stl, creating std::map names keys , value texture, here code, segmentation fault error @ line 11:

#include "texturemanager.h" std::map<std::string,sf::texture> createtexturearray(){ std::map<std::string,sf::texture> texturearray; std::vector<std::string>::iterator strit; std::string fname; for(strit = texturefilelist().begin(); strit != texturefilelist().end(); strit++){ sf::texture texture; fname = *strit; if(fname[fname.size()] == 'g' && fname[fname.size()-1] == 'p' && fname[fname.size()-2] == 'j' && fname[fname.size()-3] == '.'){ texture.loadfromfile(fname); texturearray[fname] = texture; } else if(fname[fname.size()] == 'g' && fname[fname.size()-1] == 'n' && fname[fname.size()-2] == 'p' && fname[fname.size()-3] == '.'){ texture.loadfromfile(fname); texturearray[fname] = texture; } } homecoming texturearray; }

i think code needed seek understand problem , if wants more of code here github repo

this not shown in question, texturefilelist returns value, means re-create of std::vector<std::string> returns. you're calling function twice, 1 time begin() , 1 time end(), means you're calling functions on different copies of vector. origin of 1 re-create has no relation end of copy. not this, copies beingness destroyed afterwards, because temporaries. instead, should store single re-create , phone call begin , end on that:

std::vector<std::string> filelist = texturefilelist(); for(strit = filelist.begin(); strit != filelist.end(); strit++){

c++ stl

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -