how to read inputs from a file and to write outputs to another file in c++ [closed]
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
精彩评论