char ch[255]; ifstream file("in.txt"); file.getline(ch, sizeof(ch)); cout << ch; file.close(); 

in.txt :

 sdfsdfsf sd fd dsfsdf dsfsd 

Compiled successfully, but displays nothing.

  • either you do not open the desired file (although this is unlikely, because the error should fly), or you have a null character read at the beginning of the file, which is considered to read the entire file as a line, or read character.by file.get (& char ), or read the same line by line, but in a while loop (! file.eof ()) - MorkOFF
  • Here it is completed, and nothing is output to the console? Probably in.txt file in the wrong directory. - avp
  • @avp, in.txt is in the same place as .exe - ololo
  • Found! The fact is that it ran in debug mode. And so all the rules. - Ololo
  • one
    Debag mode here should not affect. You would check if the file opened successfully. It needs to be done under any system :-) And yet, it is better to specify the absolute path to the file, and then you never know where your program will run? - VladD

0