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

怎么打开CMD就到指定目录

2013-01-21 
如何打开CMD就到指定目录?每次打开CMD都要手动输入路径,能不能编个控制台程序让CMD打开就到指定目录呢?#in

如何打开CMD就到指定目录?
每次打开CMD都要手动输入路径,能不能编个控制台程序让CMD打开就到指定目录呢?

#include <iostream>
 #include <cstdlib> 
 using namespace std;
 
 int main()
 {
     const char *buf="cd \\ \n e: \n cd ***\\***\\***\";
     //const char *tmp="ping 101*29.36.98";  
     //system("start cmd.exe");
     system(buf);
     system("pause");
     return 0;
 }

[解决办法]
该输入的还是要动手输入,
[解决办法]

//自己改改
#include <iostream>  
#include <string>  
using namespace std;  
int main(int argc, char *argv[])  
{  
char dir[100];  
string cmdlines;  
int wc;  
cmdlines = argv[0];  
wc = cmdlines.find_last_of("//");  
if (wc != string::npos)  
{  
cmdlines = cmdlines.substr(0,wc);  
}  
else  
{  
cout <<"不能找到字符串。"<<endl;  
}  
int len = cmdlines.length();  
cmdlines.copy(dir,len);  
//sprintf(dir,"start cmd /k cd /d ",dir);  
sprintf(dir,"start cmd /k cd /d ",dir);  
system(dir);  
system("pause");  
return 0;  

热点排行