2
asio 소켓에서 복사하지 않고 std :: string으로 읽으려고합니다. 이 구현은 작동하는 것으로 보이지만 신뢰할 수 있는지 확실하지 않습니다.asio :: ip :: tcp :: socket :: std :: string 직접 쓰기
string read(int bytes)
{
string str;
str.resize(bytes);
char* buffer = (char*) str.data();
//socket is declared as class member
asio::read(socket,asio::buffer(buffer,bytes));
return str;
}
귀하의 질문은 "std :: string' 버퍼에 직접 쓸 수 있습니까?"라는 일반적인 범주에 속합니다. [중복처럼 보입니다] (http://stackoverflow.com/questions/25169915/is-writing-to-str0-buffer-of-a-stdstring-well-defined-behaviour-in-c11) – PaulMcKenzie
당신을 확신하지 못하게하는 이유 ? –
@PaulMcKenzie 그래, 그게 내가 찾고있는 답변 이었지만'string.data()'와'& string [0]'이 같은가요? – Freggar