user2386653
user2386653

Reputation:

Convert byte string to normal string in C++

I have the following situation:

I'm actually trying to read streamdata from a server into a label in Visual Studio:

//Receive a reply from the server
if((recv_size = recv(ConnectSocket , server_reply , 2000 , 0)) == SOCKET_ERROR){
    MessageBox::Show("recv failed","");
    //exit(1);
}

this->label1->Text = Convert::ToString(server_reply[0]);

example result:
ANAG;FCA;11:20:27;NL0010877643;FIAT CHRYSLER AUTO;16.85;0.0;0

when I get it into my program, I have it like: 657865...

which I think is the byte representation of the corresponding characters (eg.: 65 = A, 78 = N, etc.).

Question is: How do I convert these bytecodes into a normal string of characters?

The server seems to be sending byte data

Thanks in advance

Upvotes: 1

Views: 17506

Answers (1)

codeteq
codeteq

Reputation: 1532

You just need to create a string from it.

#include <iostream>
#include <string>

using namespace std;

int main()
{
  char byteArray[] = { 65, 78, 65, 71 }; // .... your input
  std::string s(byteArray, sizeof(byteArray));
  cout << s;
  return 0;
}

Upvotes: 2

Related Questions