了解しました。あるファイルから読み取り、別のファイルに書き込もうとしています。
最初のファイルから情報を取得するなど、他に追加するものがありますが、テストのために、2番目のファイルに書き込もうとしています。
私の理解では、dp2()呼び出しの後のすべてが2番目のパラメーターに出力されます。右?
using namespace std;
using std::string;
using std::ostream;
using std::endl;
string str;
int main(){
int file= open("./input.txt", O_CREAT | O_RDWR | O_APPEND, S_IRUSR | S_IWUSR);
if(file==-1){
cout<<"Error: "<<errno<<endl;
}
int file2= open("./output.txt", O_CREAT | O_RDWR | O_APPEND, S_IRUSR | S_IWUSR);
if(file2==-1){
cout<<"Error: "<<errno<<endl;
}
int retval = dup2(file,file2);
if(retval == -1){
cout<<"Error: "<<errno;
}
printf("yeah");
close(file);
}