嘿,大家好!即使errcheck將具有非零值,該位代碼始終返回0。如果我使用return 1;它按預期工作。請幫忙?C++不能返回變量
int errcheck = system(docommand.c_str());
if (errcheck != 0)
{
cerr << "Could not retrieve tarball!" << " Errcheck status (debug): " << errcheck << endl;
return errcheck;
}
下面是完整的代碼:
#include <iostream>
#include <sys/stat.h>
#include <sys/types.h>
#include <stdlib.h>
#include <string>
using namespace std;
int main(int argc, char* argv[])
{
umask(0);
mkdir("/tmp/.aget", 0755);
chdir("/tmp/.aget");
for (int i = 1; i < argc; i++)
{
string target(argv[i]);
string docommand("");
string s1("wget -q http://aur.archlinux.org/packages/");
string s2("/");
string s3(".tar.gz");
docommand += s1;
docommand += target;
docommand += s2;
docommand += target;
docommand += s3;
cout << "Downloading AUR tarball for '" << target << "'..." << endl;
int errcheck = system(docommand.c_str());
if (errcheck != 0)
{
cerr << "Could not retrieve tarball!" << " Errcheck status (debug): " << errcheck << endl;
return errcheck;
}
}
for (int i = 1; i < argc; i++)
{
string target(argv[i]);
string docommand("");
string s1("tar xf ");
string s2(".tar.gz");
docommand += s1;
docommand += target;
docommand += s2;
cout << "Extracting '" << target << ".tar.gz'..." << endl;
system(docommand.c_str());
}
for (int i = 1; i < argc; i++)
{
string target(argv[i]);
string docommand("");
chdir("/tmp/.aget");
chdir(target.c_str());
system("makepkg -csim --noconfirm > /dev/null");
}
rmdir("/tmp/.aget");
return 0;
}
顯示周圍的代碼,該代碼所在函數或方法的返回類型是什麼? – unwind 2011-04-27 18:05:15
顯示函數原型,以及如何檢查返回值。這可能是簽名問題。返回值限制等 – 2011-04-27 18:06:02
好的,我添加了完整的源代碼。 – lupusarcanus 2011-04-27 18:09:57