I'm building a ftp server and this is a message sent from the client to the server to check whether the file size is approved by the server. I need to use char* in function write so I want to convert string to char*. The string structure is fileName#fileSize(test.txt#37). I tried c_str but got rubbish in the end.
Let have a look at the following code:
string str(filenameDes);
str += HASHTAG;
str += to_string(fileSize);
cout << "str: " << str << endl;
char * pchar = str.c_str();
// sending file size to server
int retVal = write(socket, pchar, strlen(pchar));
Although when i want to print the message in the server using cout i get this output: test2#37�� or something close to it, meaning i get rubbish in the end.
How do i clean the rubbish? or any other command to convert to char* ?