簡體   English   中英

套接字write()函數的問題

[英]Issues with socket write() function

我在獲取套接字的write()參數正常工作時遇到問題。 我建立了自己的write()包裝器來接受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;
}

你需要這條線

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

讀書

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM