I could really do with some help converting to System::String ^.
I will be reading arguments into my program which are of type 'char*'
using:
int main(int argc, char* argv[])
However, I want to use the ping class (link below) which takes inputs of type 'System::String ^', and when I try to put argv[1] into the code like so:
PingReply ^ reply = pingSender->Send( argv[ 1 ], timeout, buffer, options );
I get the following error:
error C2664: 'System::Net::NetworkInformation::PingReply ^System::Net::NetworkInformation::Ping::Send(System::String ^,int,cli::array<Type> ^,System::Net::NetworkInformation::PingOptions ^)' : |
cannot convert parameter 1 from 'char *' to 'System::String ^' |
Also, as this part of the code is within a separate function from the main function, and therefore doesn't have access to argv[] (correct me if I'm wrong) I have tried converting the arguments to a
vector as at compile time I do not know how many arguments will be passed in. I have declared
vector<string> IPaddresses;
as a global variable. And at the beginning of the main function
I put the arguments into this vector by:
1 2 3
|
for(int i=0; i<=(argc-1); i++){
IPaddresses[i] = argv[i+1];
}
|
Then when I try:
PingReply ^ reply = pingSender->Send( IPaddresses[1], timeout, buffer, options );
I get the following error:
error C2664: 'System::Net::NetworkInformation::PingReply
^System::Net::NetworkInformation::Ping::Send(System::String ^,int,cli::array<Type> ^,System::Net::NetworkInformation::PingOptions ^)' : |
cannot convert parameter 1 from 'std::basic_string<_Elem,_Traits,_Ax>' to 'System::String ^' |
Does anybody know the best way to convert to 'System::String ^'?
Or does anybody know a better way to do what I am trying to achieve?
Any advice whatsoever would be very much appreciated.
Thanks very much for your time,
Meerkat
here's a link to information on the ping class:
http://msdn.microsoft.com/en-us/library/system.net.networkinformation.ping.aspx
I'm pretty much just wanting to change the first example code slightly