我有以下问题。我使用以下函数从缓冲区接收字符串,直到出现换行符。
string get_all_buf(int sock) {
int n = 1, total = 0, found = 0;
char c;
char temp[1024*1024];
string antw = "";
while (!found) {
n = recv(sock, &temp[total], sizeof(temp) - total - 1, 0);
if (n == -1) {
break;
}
total += n;
temp[total] = '\0';
found = (strchr(temp, '\n') != 0);
if (found == 0){
found = (strchr(temp, '\r\n') != 0);
}
}
antw = temp;
size_t foundIndex = antw.find("\r\n");
if (foundIndex != antw.npos)
antw.erase ( antw.find ("\r\n"), 2 );
foundIndex = antw.find("\n");
if (foundIndex != antw.npos)
antw.erase ( antw.find ("\n"), 2 );
return answ;
}
所以像这样使用它:
string an = get_all_buf(sClient);
如果我创建一个 exe 文件,一切正常。但是,如果我创建一个 dll 并使用 rundll32 运行它,则应用程序将在“ string an = get_all_buf(sClient);
”处关闭而没有任何错误消息......
我试图解决这个问题已经好几个小时了,我现在有点绝望......
PS 对明显的错误或糟糕的编码风格表示抱歉,我刚开始学习 C++。