把delphi一段代码转换成c++
请高手帮忙把下列代码转换成c++,谢谢了
procedure SocketSend(Data:String);
var Error:Integer;
begin
if Data='' then exit;
EnterCriticalSection(Cri); //进入临界区
vSocketWait:=True;
if isDebug then
Print2(#13#10+Data+#13#10,FOREGROUND_INTENSITY + FOREGROUND_BLUE +BACKGROUND_BLUE);
Data:=AnsiToUTF8(Data);
Error:=send(S,Data[1],Length(Data),0);
LeaveCriticalSection(Cri); //退出临界区
if Error<=0 then
begin
SocketConnect(True);
SocketSend(Data);
end;
end;
function GetValue(Code,v:String):String;
var Temp,i:Integer;
begin
Result:='';
if Pos(v,Code)=0 then exit;
Result:=Code;
Temp:=Pos(v,Result)+Length(v);
Result:=Copy(Result,Temp,Length(Result)-Temp);
if Pos('&',Result)>0 then
Result:=Copy(Result,1,Pos('&',Result)-1);
if (Result<>'') and (Result[Length(Result)]=#13) then Result:=Copy(Result,1,Length(Result)-1);
For i:=1 to Length(Result)-1 do
if (Result[i]=#13) and (Result[i+1]<>#10) then Result[i]:=#10;
end;
[解决办法]
注意一些细节。
void __fastcall SocketSend(String Data){ if (Data == "") return; EnterCriticalSection(&Cri); //进入临界区 vSocketWait = true; if (isDebug) Print2(String("\r\n") + Data + String("\r\n"), FOREGROUND_INTENSITY + FOREGROUND_BLUE + BACKGROUND_BLUE); Data = AnsiToUTF8(Data); int Error = send(S, Data[1], Data.Length, 0); LeaveCriticalSection(&Cri); //退出临界区 if (Error <= 0) { SocketConnect(true); SocketSend(Data); }}String GetValue(String Code, String v){ String strResult(""); if (Code.Pos(v) == 0) return strResult; strResult = Code; int Temp = strResult.Pos(v) + v.Length(); strResult = strResult.SubString(Temp, strResult.Length() - Temp); if (strResult.Pos('&') > 0) strResult = strResult.SubString(1, strResult.Pos('&') - 1); if (strResult != "" && strResult[strResult.Length()] == 13) strResult = strResult.SubString(1, strResult.Length() - 1); for (int i = 1; i < strResult.Length(); i++) if (strResult[i] == 13 && strResult[i+1] != 10) strResult[i] = 10;}
[解决办法]
刚看了看,GetValue函数最后少了一句:
return strResult;