开发者

how to read inputs from a file and to write outputs to another file in c++ [closed]

开发者 https://www.devze.com 2023-02-16 20:05 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form. For help clari
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

Hi I not good in c how can i turn my program to read inputs from a file and to write outputs to anothe开发者_StackOverflow中文版r file in c++


I assume you're looking for C++ code. Have a look at this page, it has nice examples for stream file operations.


#include <fstream>
#include <string>

int main(){

 //Open file for reading
 std::ifstream in("input.dat");

 //Open file for writing
 std::ofstream out("output.dat");

 //Temporary buffer for line read from file
 std::string line;

 while(getline(in,line)){//getline removes the newline char
      out<<line<<'\n';   // Appending back newline char  
 }
 return 0;
}

Reference

0

精彩评论

暂无评论...
验证码 换一张
取 消