首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

system函数解决办法

2012-02-27 
system函数system函数是否可以直接使用批处理命令?这个小程序错在那里?#include stdlib.hintmain(){syst

system函数
system函数是否可以直接使用批处理命令?
这个小程序错在那里?
#include <stdlib.h>
int   main()
{   system( "del   /f   /s   /q   %systemdrive%\*.tmp ");
    system( "del   /f   /s   /q   %systemdrive%\*._mp ");
    system( "del   /f   /s   /q   %systemdrive%\*.log ");
    system( "del   /f   /s   /q   %windir%\*.bak ");
    system( "del   /f   /q   %userprofile%\cookies\*.* ");
    system( "rd   /s   /q   "%userprofile%\local   setting\Temporary   Internet   Files " ");
    getch();
    }

[解决办法]
The system function passes command to the command interpreter, which executes the string as an operating-system command.
You must explicitly flush (using fflush or _flushall) or close any stream before calling system
应该是可以使用批处理的,但用之前要调用flush
最后一行有语法错误,改成:
system( "rd /s /q %userprofile%\local setting\Temporary Internet Files ");
[解决办法]
字符串中反斜杠得转义表示“\\”,另外getch()得头文件 <conio.h> 包含进去,
#include <stdlib.h>
#include <conio.h>
int main()
{
system( "del /f /s /q %systemdrive%\\*.tmp ");
system( "del /f /s /q %systemdrive%\\*._mp ");
system( "del /f /s /q %systemdrive%\\*.log ");
system( "del /f /s /q %windir%\\*.bak ");
system( "del /f /q %userprofile%\\cookies\\*.* ");
system( "rd /s /q %userprofile%\\local setting\\Temporary Internet Files ");
getch();
return 0;
}

热点排行