我试了一下这样可以
#include<iostream.h>
#include<stdlib.h>
#include<string>
using namespace std;
#define MAXBUFLEN 100
int main(int argc,char *argv[]){
string text;
string cmdstr;
if(argc>1){
text = (string)argv[1];
cmdstr="attrib " + text;
system(cmdstr.c_str ());
}
else{
cout<<"文件名不给一个?"<<endl;
}
return 0;
}
下面是MSDN中的解释
system, _wsystem
Execute a command.
int system( const char *command );
int _wsystem( const wchar_t *command );
Routine Required Header Compatibility
system <process.h> or <stdlib.h> ANSI, Win 95, Win NT
_wsystem <process.h> or <stdlib.h> or <wchar.h> Win NT
Example
/* SYSTEM.C: This program uses
* system to TYPE its source file.
*/
#include <process.h>
void main( void )
{
system( "type system.c" );
}
Output
/* SYSTEM.C: This program uses
* system to TYPE its source file.
*/
#include <process.h>
void main( void )
{
system( "type system.c" );
}作者: maclover815 时间: 2007-12-14 13:19 支持一下