Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/146.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++;编译错误:应为‘’;或‘’;在‘之前;(&x2019;代币 >非常强的C++编译语法错误,我无法找到解决方案:我对C++是相当新的,并且对函数作为参数传递进行了读取。编译错误对我来说没有意义,因为我已经一遍遍地阅读代码。请帮助。< /P>_C++_Compiler Errors_Syntax Error - Fatal编程技术网

C++;编译错误:应为‘’;或‘’;在‘之前;(&x2019;代币 >非常强的C++编译语法错误,我无法找到解决方案:我对C++是相当新的,并且对函数作为参数传递进行了读取。编译错误对我来说没有意义,因为我已经一遍遍地阅读代码。请帮助。< /P>

C++;编译错误:应为‘’;或‘’;在‘之前;(&x2019;代币 >非常强的C++编译语法错误,我无法找到解决方案:我对C++是相当新的,并且对函数作为参数传递进行了读取。编译错误对我来说没有意义,因为我已经一遍遍地阅读代码。请帮助。< /P>,c++,compiler-errors,syntax-error,C++,Compiler Errors,Syntax Error,编辑:我删除了waitpid(pid\t,int,int)并只使用system()命令。谢谢大家的帮助 #include <stdlib.h> #include <sys/types.h> #include <unistd.h> #include <sys/wait.h> int main(){ /* puts apt-get purge text into ~$ purge_e_output */ system("sudo apt-ge

编辑:我删除了waitpid(pid\t,int,int)并只使用system()命令。谢谢大家的帮助

#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/wait.h>

int main(){
/* puts apt-get purge text into ~$ purge_e_output */
    system("sudo apt-get purge enlightenment > purge_e_output.txt");
    system("echo **Pid of apt-get**");
    system("pidof apt-get");
    try{
        pid_t waitpid(pid_t getpid("apt-get"), int *statusPtr, int WUNTRACED);
    } catch(...){}
    system("echo **REMOVING ENGLIGHTENMENT**"); 
    system("sudo apt-get purge enlightenment");
    system("pidof apt-get");
    try{
        pid_t waitpid(pid_t getpid("apt-get"), int *statusPtr, int WUNTRACED);
    } catch(...){}

/* puts apt-get autoremove text into ~$ autoremove_e_output */
    system("sudo apt-get autoremove > autoremove_e_output.txt");
    system("echo **Pid of apt-get**");
    system("pidof apt-get");
    try{
        pid_t waitpid(pid_t getpid("apt-get"), int *statusPtr, int WUNTRACED);
    } catch(...){}

    system("echo **REMOVING E DATA**"); 
    system("sudo apt-get autoremove");
    system("echo **Pid of apt-get**");
    system("pidof apt-get");
    try{
        pid_t waitpid(pid_t getpid("apt-get"), int *statusPtr, int WUNTRACED);
    } catch(...){}

/* puts apt-get autoclean text into ~$ autoclean_e_output */
    system("sudo apt-get autoclean > autoclean_e_output.txt");
    system("echo **Pid of apt-get**");
    system("pidof apt-get");
    try{
        pid_t waitpid(pid_t getpid("apt-get"), int *statusPtr, int WUNTRACED);
    } catch(...){}
    system("echo **CLEANING**");    
    system("sudo apt-get autoclean");
    system("echo **Pid of apt-get**");
    system("pidof apt-get");
    try{
        pid_t waitpid(pid_t getpid("apt-get"), int *statusPtr, int WUNTRACED);
    } catch(...){}

/* reinstall englightenment */
    system("echo **REINSTALLING**");    
    system("sudo apt-get install enlightenment");
    system("echo **Pid of apt-get**");
    system("pidof apt-get");
    try{
        pid_t waitpid(pid_t getpid("apt-get"), int *statusPtr, int WUNTRACED);
    } catch(...){}

/* logs */
    system("echo && echo Logs for wtf just happened:");
    system("echo && echo ~$ purge_e_output.txt && echo ~$ autoremove_e_output.txt && echo ~$ autoclean_e_output.txt");

}
你不能这样做

    pid_t waitpid(pid_t getpid("apt-get"), int *statusPtr, int WUNTRACED);
相反,您需要实际创建要传递给此函数的变量的实例

    pid_t pid = getpid();
    int status = // set to some value that you choose
然后你可以这样调用你的函数

    pid_t pid2 = waitpid(pid, &status, WUNTRACED);
现在
pid2
waitpid
函数返回的值。
我强烈建议你多读一点书——无论是书还是教程——因为你的问题表明你对这门语言还没有很强的掌握。我的意思是,这完全没有冒犯你的意思——只是想帮忙而已。

这在那个地方没有意义:

pid_t waitpid(pid_t getpid("apt-get"), int *statusPtr, int WUNTRACED);
线路

pid_t waitpid(pid_t getpid("apt-get"), int *statusPtr, int WUNTRACED);
看起来像一个函数声明,对我和C++编译器来说,看起来你想声明一个名为“代码> WaistPix/Cuth.>的函数,它的返回类型是“代码> PIDYT < /COD>”,它有三个参数,一个“代码> PIDyt < /Cube >,一个代码> int */COD>,还有一个<代码> int >代码>。但是,参数的名称不能是代码> GETPID(“apt get”),因此除了这是函数声明在文件中的错误位置外,您不能将其解释为函数声明,因为它试图使用函数调用作为参数的名称

相反,如果您试图将此行解释为对名为
waitpid
(已定义)的函数的函数调用,
getpid(“apt-get”)
作为参数是有意义的,因为它意味着您希望将
getpid
函数的结果作为第一个参数传递给
waitpid
函数。但是,该行的其余部分对于函数调用来说是不正确的语法,因为函数调用的参数类型不应该内联指定-您应该e传递已经定义为变量或函数的参数。对
waitpid
函数的语法正确调用可能如下所示:

int* statusPtr = ...;
int WUNTRACED = ...;
pid_t myPid = waitpid(getpid("apt-get"), &statusPtr, WUNTRACED);
以下定义可能出现在其他地方:

pid_t waitpid(pid_t pid, int *statusPtr, int WUNTRACED) {
    ...
}

您正在尝试生成或调用该函数吗?您不能在其他函数中生成它们,这不是调用函数的正确方式。调用函数时,不要指定参数的类型…以及1)为什么调用waitpid?2)shell脚本更适合此任务。除此之外,您不需要waitpid()对于调用通过系统()调用的东西,我从来没有见过一个进程名……我认为GETPIDE()调用不太可能是WaITPIDE()或GETPID.()实际上会抛出C++异常:-:<代码> pIDyt WaPID(PIDyt GETPID(“APT get”),int *StasuStR,int WunTraceDebug);是一个语法错误。如果您能告诉我们它应该做什么,这将很有帮助。
system()
调用将生成并等待进程完成,因此您将永远无法找到进程ID(到达该行时,进程将消失)。如果您确实需要这样做,请更新您的问题。没有冒犯您的意思,但是我删除了waitpid等,应用程序将只使用system()命令。它看起来更像一个函数声明(定义包括函数体,
{…}
)。但是不是有效的参数声明,所以整个过程只是语法错误。
pid_t waitpid(pid_t pid, int *statusPtr, int WUNTRACED) {
    ...
}