开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜