Code Snippets

  

C++ Source Code


Welcome to Dream.In.Code
Become a C++ Expert!

Join 149,624 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,965 people online right now. Registration is fast and FREE... Join Now!



Submitted By: Xing
Actions:
Rating:
Views: 4,681

Language: C++

Last Modified: October 6, 2006

Snippet


  1. #include <fstream>
  2. #include <string>
  3.  
  4. int main(){
  5.      
  6.      //Open file for reading
  7.      std::ifstream in("input.dat");
  8.      
  9.      //Open file for writing
  10.      std::ofstream out("output.dat");
  11.      
  12.      //Temporary buffer for line read from file
  13.      std::string line;
  14.      
  15.      while(getline(in,line)){//getline removes the newline char
  16.           out<<line<<'\n';   // Appending back newline char 
  17.      }
  18.      return 0;
  19. }
  20.  

Copy & Paste


Comments


There are currently no comments for this snippet. Be the first to comment!

Add comment


You must be registered and logged on to </dream.in.code> to leave comments.




Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month