c++ - Trying to append a char string -
i know basic question can't seem append char string (\r\n) another. have tried using arrays (strcpy) , string objects no progress. send string java applet need append \r\n characters or sit , wait them. when use stirng c_str() function a
c:\ucdhb2\gaia\async_ssl\no4\basic.cpp|163|error: request member 'c_str' in 'readit', of non-class type 'std::string*'|
error. appreciated.
char readit[45]; cin >> readit; strcpy( readit, "\r\n" ); ssl_write( ssl, readit, strlen(readit)); // doesn't work // ssl_write( ssl, "this works\n\r", strlen("this works\n\r")); // works
a string
should need.
std::string readit; std::getline(std::cin, readit); readit += "\r\n"; ssl_write(ssl, readit.data(), readit.size());
as other commentators have noted, sample code needed use strcat
rather strcpy
. but, if go using char
arrays, need check buffer overflow. std::string
won't overflow.
Comments
Post a Comment