This code is meant to output Hello World. but it outputs 0x22fed8

前端 未结 4 2004
抹茶落季
抹茶落季 2020-12-08 11:59

I\'m learning File Handling in C++, but there is a problem here. I am trying to read a file. This code is meant to output Hello World. but it outputs 0x22fed8.



        
4条回答
  •  Happy的楠姐
    2020-12-08 12:29

    EDIT: With mrree's suggestions.

    ifstream fin("file.txt");
    
    if (fin.is_open() == false) {
      // error
    }
    
    string line;
    
    while( getline(fin, line) ) {  
      cout << line;
    }
    

提交回复
热议问题