0
有人可以解釋我爲什麼使用這兩種類型的回報?QT Creator,return(C++)
int parse(QTextStream& out, const QString fileName) {
QDomDocument doc;
QFile file(fileName);
if (!file.open(QIODevice::ReadOnly|QIODevice::Text)) {
out<<"Datei "<<fileName<<" nicht lesbar"<<endl;
> return 1;
}
QString errorStr;
int errorLine;
if (!doc.setContent(&file, false, &errorStr, &errorLine)) {
out<<"Fehler in Zeile "<<errorLine<<": "<<errorStr<<endl;
> return 2;
}
...
}
這裏停留另一program.Why的一部分代碼在這裏不`噸的工作方式相同與
返回0;
?
int main(int argc, char *argv[])
{
QTextStream out(stdout);
out.setCodec("UTF-8");
if (argc != 3) {
out<<"Usage: "<<argv[0]<<" XML-Datei ist nicht vorhanden."<<endl;
return(1);
}
List wayList(out, argv[1]);
out<<"DOM-Baum gelesen."<<endl;
wayList.convert(argv[2]);
return 1;
}
「return」沒有不同的「類型」。你做'返回;'其中''是你想要的函數的返回值。在你的代碼中,函數返回不同的值來表示請求操作的不同結果。 –