Question about Operator "<<"

//--------------------------------------------------------------
void GameManager::LoadLevel(std::string filename)
{
std::string txtname;
std::ifstream in;
in.open(filename);
if(in.fail())
exit(0001);
while(!in.eof())
{
GameObject* temp = new GameObject;
in >> txtname >> temp->m_state >>temp->m_offset.x >>temp->m_offset.y;


m_objs.push_back(temp);
m_objs[m_objs.size()-1]->LoadAnimations(txtname);
}
in.close();
}
//--------------------------------------------------
//For example my filename is "level1.txt"
// How does the txtname's value become to "level1.txt"?
// if in>>txtname gives txtname the value "level1.txt"? if it is. Why don't
// just directly use filename,but create a new string txtname?
//--------------------------------------------------------
// oh right, I am sorry guys. I made a mistake. the txtname did not become "level1.text".
// It became to "link_sheet.txt" which is the first ward in level1.text. now i am
// understand think you guys for help.
// @Peter87
//
//
Last edited on
I suggest that before your int main(), do this
#define filename "level1.txt" // {no semicolon';' here}
and don't pass the filename as parameter.
The only reason txtname would become "level1.txt" is if that is what the file contain.
@newbiee999, that's awful advice. OP, do not listen to that.


OP, why not just std::string txtname = filename ?

I don't fully understand what you're asking.
@ResidentBiscuit I have the same question, why I need the txtname.

my main question is:
here "in" is a ifstream variable so what will happen to "txtname" when "in>>txtname".
in>>txtname will read the next word in the file and store it in txtname.
Topic archived. No new replies allowed.