0

ソケットの引数がwrite()正常に機能しない問題が発生しています。orwrite()を受け入れる独自のラッパーを作成しました。コードとコンパイラ エラーは以下のとおりです。タイstd::stringchar *

ftp.cpp:136:50: error: cannot convert 'std::basic_string<_CharT, _Traits, 
_Alloc>::length<char, std::char_traits<char>, std::allocator<char> >' from type 
'std::basic_string<char>::size_type (std::basic_string<char>::)()const {aka long unsigned 
int (std::basic_string<char>::)()const}' to type 'size_t {aka long unsigned int}'



int FTP::_write(std::string data)
{
    if (data != "")
    {
        int n = write(sockfd, data.c_str(), data.length); // this line is what the compiler is complaining about
        log->write("Write: " + data);
        if (n < 1)
            throw new FTPException(100, "Failed to write.");
    }
    else
    {
        int n = write(sockfd, buffer, strlen(buffer) + 1);
        log->write("Write: " + std::string(buffer));
        if (n < 1) 
            throw new FTPException(100, "Failed to write.");
    }
    return 1;
}
4

1 に答える 1

3

この行が必要です

int n = write(sockfd, data.c_str(), data.length);

読む

int n = write(sockfd, data.c_str(), data.length());
于 2013-02-10T06:52:14.413 に答える