好吧,我正在尝试从一个文件中读取并写入另一个文件。
我还有其他要添加的内容,例如从第一个文件中获取信息,但为了测试,我试图让它写入第二个文件。
我的理解是 dp2() 调用之后的所有内容都会输出到第二个参数。对?
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);
}