Jaki postawić warunek przy “if” i “else if” żeby wyświetlał brak połączenia lub połączenie nawiązane w zależności czy nie ma lub jest połączenie.
#include
#include
#include
#include
using namespace std;
static string host;
int main()
{
cin >> host;
system (("ping " + host).c_str());
cout << endl;
if (host == 0)
{
cout<
getch();
}
else if (host == 1)
{
cout<
getch();
}
return 0;
}
_alex
([alex])
#2
Nie ma takiej możliwości.
Jeżeli chcesz analizować co zwróciła komenda systemowa (jaki ERRORLEVEL) to nie uruchamiaj tego przez funkcje system().
to w jaki sposób moge uruchomic ??? żeby wyświetlało brak lub połączenie nawiązane
_alex
([alex])
#4
Np. przez CreateProcess().
lub:
if (system(host)) cout<<“brak polaczenia”<
else cout<<“polaczenie nawiazane”<
cin.sync();
cin.get();
nie chce isc przy if jakiś błąd
#include
#include
#include
#include
using namespace std;
static string host;
int main()
{
host = "www.wp.pl";
if (system(host)) cout<<"brak polaczenia"<
else cout<<"polaczenie nawiazane"<
cin.sync();
cin.get();
return 0;
}
_alex
([alex])
#6
samo wywołanie zrób tak jak miałeś, to co podałem zadziała tylko przy deklaracji:
char host[]=“ping www.wp.pl”;
Dalej nie chce działać, coś jest chyba źle z " char host[]=“ping http://www.wp.pl”;"
występuje taki komunikat błędu:
invalid operands of types `const char[6]' and `char[15]' to binary `operator+'
tu jest ten kod programu:
#include
//#include
//#include
#include
using namespace std;
//static string host;
int main()
{
char host[]="ping www.wp.pl";
system (("ping " + host).c_str());
if (system(host)) cout<<"brak polaczenia"<
else cout<<"polaczenie nawiazane"<
cin.sync();
cin.get();
return 0;
}
_alex
([alex])
#8
Nie możesz dodać do char* inny char*
albo:
string host(“www.wp.pl”);
albo:
char host[]=“www.wp.pl”;
system ((string("ping ") + host).c_str());
albo:
system(host);