c++ - Reading and displaying a file -


I am having problems displaying this file. I try to create a file and display it in an output screen I am doing But Milan is not working, it is getting me in line 40 as "unannounced". I have tried to chant things and I do not do anything. What's the problem?

  #include & lt; Iostream & gt; # Include & lt; Fstream & gt; # Include & lt; Stdlib.h & gt; #include & lt; String & gt; using namespace std; Int main () {char filename [] = "Hello.txt"; String line = "hello, this is my output file"; Offream outfile; OutFile.open (filename); If (OutFile.fail ()) // To successfully open the check, {cout & lt; & Lt; "Named file not found \ n"; Exit (1); } Outfile & lt; & Lt; Line; If (OutFile.is_open ()) OutFile.getline (line); OutFile.close (); System ("pause"); }  

std :: getline () is an independent Function, not member function The member function version is for the raw letter arrays and when you are using std :: string , the free function is justified.

  std :: getline (outfile, line);  

Also note that std :: getline () works with the object type std :: istream , and Since you are trying to input your outfile object should not be std :: ofstream . .

Change is a bidirectional file stream from outfile std :: fstream .


Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -