#include<iostream>
#include<stdlib.h>
#include<fstream>
#include<cstring>
#include<string>
using namespace std;
int main()
{
ifstream input;
char c;
string ip;
char pingip[35];
string time="";
bool STATE=false;
cout<<"Please input the host you want to ping:"<<endl;
cin>>ip;
ip="ping -n 1 "+ip+" > tmp.txt";
//cout<<ip;
strcpy( pingip, ip.c_str() );
system(pingip);
input.open("tmp.txt",ios::in);
int num=0;
while(input>>c&&c!=EOF){
//num++;
if(c=='='||c=='<')
{
num++;
input>>c;
}
if(num==2)
{
if(c=='T')
{
break;
}
time+=c;
}
}
if(time.at(0)<49||time.at(0)>58)
{
time="Request timed out";
}
cout<<time<<endl;
system("pause");
return 0;
}
好像还是不行? 但是在命令行执行却可以成功! 你编译一下帮我看看吧!
追答这个不好解释了啊
命令行可以 windows双击不可以 难道有执行用户权限的问题