在我的程序中使用时出现一些奇怪的行为cout
,类似于以下内容:
...
char *input = realpath(argv[1], NULL);
char *output = argv[2];
char *tarout = new char[strlen(output)+6];
strcpy(tarout, output);
strcat(tarout, ".temp");
cout << "Tarout: " << tarout << endl;
int tRet = tarball(input, tarout);
if(tRet != 1) {
cerr << "Error: Could not compress directory!\nHalting package creation!" << endl;
return 0;
}
int gRet = gzip(tarout, output);
if(gRet != 1) {
cerr << "Error: Could not compress directory!\nHalting package creation!" << endl;
return 0;
} else {
cout << "TAROUT: " << tarout << endl;
if((remove(tarout))!=0) {
cerr << "Warning: Could not delete temporary file!" << endl;
return 0;
}
}
...
基本上这个程序会创建一个 tar 文件,然后用 gzip 压缩它,这不是 100% 的实际代码,所以它可能不会给出与我收到的相同的奇怪行为。
如果我删除了第一个cout << "TAROUT: " << tarout << endl;
,第二个cout << "TAROUT: " << tarout << endl;
将不会返回任何内容,并且临时文件不会被删除,这是为什么呢?