hi, i'm getting a message from a socket like char *datos3="UNBLOCK"; size_t len2 = socket.read_some(boost::asio::buffer(buf2), error2); datos2=(buf2.data()); *//and compare datos2 and datos3* ost::is_equal test; if (test(datos2,datos3)) { std::cout << "Equal" << endl; return; } else std::cout << "NO Equal" << endl; but the string in Datos2 is : UNBLOCK@= ��< , what i got that strange charateres? thanks Ing Pedro Alonso Chaparro Valero Ciudad Politecnica de la Innovación iTEAM - Mobile Communications Group Polytechnic University of Valencia C\ Camino de Vera S/N, Edificio 8G 46022 Valencia, Spain
char *datos3="UNBLOCK"; size_t len2 = socket.read_some(boost::asio::buffer(buf2), error2);
datos2=(buf2.data());
//and compare datos2 and datos3
ost::is_equal test;
if (test(datos2,datos3)) { std::cout << "Equal" << endl; return; } else std::cout << "NO Equal" << endl;
but the string in Datos2 is : UNBLOCK@ = ��< , what i got that strange charateres?
Are you sure that you get from the socket null-terminated sequence of characters? If it's not null-terminated, then set null-terminator manually - or just do not use functions that expect null-terminated strings.
now i sending a message with null terminator \0 but i continue having the
same problem, What is an example of function that does not expect null
terminated strings?? there is not some function like where i can pass too
the lenght of the string , something like datos2=(buf2.data,lenght)?
thanks
2010/2/10 Igor R
char *datos3="UNBLOCK"; size_t len2 = socket.read_some(boost::asio::buffer(buf2), error2);
datos2=(buf2.data());
//and compare datos2 and datos3
ost::is_equal test;
if (test(datos2,datos3)) { std::cout << "Equal" << endl; return; } else std::cout << "NO Equal" << endl;
but the string in Datos2 is : UNBLOCK@ = ��< , what i got that strange charateres?
Are you sure that you get from the socket null-terminated sequence of characters? If it's not null-terminated, then set null-terminator manually - or just do not use functions that expect null-terminated strings. _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
-- Ing Pedro Alonso Chaparro Valero Ciudad Politecnica de la Innovación iTEAM - Mobile Communications Group Polytechnic University of Valencia C\ Camino de Vera S/N, Edificio 8G 46022 Valencia, Spain
What is an example of function that does not expect null terminated strings?? there is not some function like where i can pass too the lenght of the string , something like datos2=(buf2.data,lenght)? thanks
In CRT you've got strcmp() that compares null-terminated C strings and strncmp() which accept the number of characters to compare. Besides, you can create std::string from n characters: std::string s(your_c_string, n); then you can compare std::string's with operator ==.
participants (2)
-
Igor R
-
pedro chaparro