[RESOLVED] Getting the length of a string of a buffer
Hello,
I have a buffer that contains words. However, the words comes from a client. I just want to get the words out. However, the buffer is being filled with rubbish after the words. Example "Manchester United&^&*#&#&##^&#@*&^^ etc.
How can I just get "Manchester United" out?
I have used the following using length and substring, but it displays everything
Code:
char buffer[256];
sock.receiveFrom(buffer,sizeof(buffer), addr);
std::string message = buffer;
int strLength = 0;
strLength = message.size();
std::cout << "The length of the string is: " << strLength << std::endl;
message = message.substr(0,strLength);
std::cout << message;
Many thanks,
Steve
Re: [RESOLVED] Getting the length of a string of a buffer
This is marked resolved with no posted solution.
Is it resolved?
If so, what did you do to resolve it? It might help someone else with a similiar problem.
Re: [RESOLVED] Getting the length of a string of a buffer
If it's not resolved, it's up to the client to indicate the end of string. If it doesn't, there's no way a program can figure out where the end is on the fly.