Answer the question
In order to leave comments, you need to log in
How to convert wstring to char* and vice versa?
Good afternoon! I'm currently learning about sockets and ran into a problem
wstring strTheNameOfTheFile = FindFileData.cFileName;
char* serial = (char*)strTheNameOfTheFile.c_str();
iResult = send(ConnectSocket, serial, (int)strlen(serial), 0);
char* echo = new char[1024];
do {
iResult = recv(AcceptSocket, echo, 1024, 0);
if (iResult > 0 && iResult == 1024) {
FILE * pFile;
stringstream ss;
ss << counter << echo;
string str(ss.str());
cout << iResult<<endl;
pFile = fopen(str.c_str(), "ab");
fwrite(echo, iResult, 1, pFile);
fclose(pFile);
}
else if (iResult < 1024 && iResult != 0) {
FILE * pFile;
stringstream ss;
ss << counter << echo;
string str(ss.str());
wstring ws(&echo[0], &echo[(int)strlen(echo)]);
wcout << ws << endl;
pFile = fopen(str.c_str(), "ab");
fwrite(echo, iResult, 1, pFile);
fclose(pFile);
counter++;
int sendD = send(AcceptSocket, sendC, 3, 0);
}
else
cout << "Disconnect..." << endl;
} while (iResult > 0);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question