I have trouble to copy a char array into a String
. The following line works fine:
String packetBufferString(packetBuffer);
But obviously I can do this only once, since packetBufferString
has to be global and cannot be declared again. The problem is that packetBuffer
changes at runtime but I can't update packetBufferString
.
The char array is set up with
char packetBuffer[UDP_TX_PACKET_MAX_SIZE];
lg, couka
If String
is std::string
then you can write
std::string packetBufferString(packetBuffer);
//
packetBufferString.assign(packetBuffer);
or
std::string packetBufferString(packetBuffer);
//
packetBufferString = packetBuffer;
provided that packetBuffer
is zero-terminated. Otherwise you can do the same (that is assigning) but using initial and ending iterators for packetBuffer
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.