简体   繁体   English

C ++ Boost - 没有找到哪个运算符采用'boost :: filesystem :: path'类型的右手操作数

[英]C++ Boost - no operator found which takes a right-hand operand of type 'boost::filesystem::path'

I'm building a client/sever application for sending files over the lan. 我正在构建一个客户端/服务器应用程序,用于通过局域网发送文件。 This is the sever application and I get the following error on my code when I'm about to get the file name. 这是服务器应用程序,当我要获取文件名时,我的代码出现以下错误。

error C2679: binary '=' : no operator found which takes a right-hand operand of type 'boost::filesystem::path' (or there is no acceptable conversion)

#include "stdafx.h"
#ifdef _WIN32 
# define _WIN32_WINNT 0x0501 
#endif 
#include <boost/asio.hpp> 
#include <boost/array.hpp> 
#include <boost/filesystem.hpp> 
#include <boost/filesystem/path.hpp>
#include <string> 
#include <fstream> 
#include <sstream> 
#include <iostream> 

std::string filename; 
std::string file; 
boost::asio::io_service io_service; 
boost::asio::ip::tcp::endpoint endpoint(boost::asio::ip::tcp::v4(), 9999); 
boost::asio::ip::tcp::acceptor acceptor(io_service, endpoint); 
boost::asio::ip::tcp::socket sock(io_service); 
boost::array<char, 4096> buffer; 

void read_handler(const boost::system::error_code &ec, std::size_t bytes_transferred) { 
    if (!ec || ec == boost::asio::error::eof){ 
        std::string data(buffer.data(), bytes_transferred); 
        if (filename.empty()) { 
            std::istringstream iss(data); 
            std::getline(iss, filename); 
            file = data; 
            file.erase(0, filename.size() + 1); 
            filename = boost::filesystem::path(filename).filename(); 
        } 
        else  
            file += data; 
        if (!ec) 
            boost::asio::async_read(sock, boost::asio::buffer(buffer), read_handler); 
        else { 
         //code
    } 
} 

//code //码

Just change this line: 只需改变这一行:

filename = boost::filesystem::path(filename).filename(); 

to this: 对此:

filename = boost::filesystem::path(filename).filename().string();

Basically the compiler is telling you that std::string does not define any assignment operator that takes a boost::filesystem::path as a parameter (or that there is no conversion it can make that will provide a type it can use as a parameter for the assignment operator). 基本上编译器告诉你std::string没有定义任何赋值运算符,它将boost::filesystem::path作为参数(或者它没有进行任何转换,它将提供一个可以用作赋值运算符的参数)。 Luckily, boost::filesystem::path provides a function that returns a string! 幸运的是, boost::filesystem::path提供了一个返回字符串的函数!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 C ++没有找到需要右手操作数的&lt;&lt;运算符 - C++ No << operator found which takes right-hand operand C++ 递归地遍历路径。 错误:未找到采用“const std::filesystem::directory_entry”类型的右手操作数的运算符 - C++ iterate through a path recursively. Error: no operator found which takes a right-hand operand of type 'const std::filesystem::directory_entry' 重载&lt;&lt;在C ++错误中的运算符:::二进制&#39;&lt;&lt;&#39;:找不到使用类型为&#39;const std :: string的右侧操作数的运算符 - Overloading the << operator in C++ error ::: binary '<<' : no operator found which takes a right-hand operand of type 'const std::string c ++错误c2679:二进制&#39;[&#39;:未找到采用&#39;SalesItem&#39;类型的右侧操作数的运算符(或者没有可接受的转换) - c++ error c2679: binary '[' : no operator found which takes a right-hand operand of type 'SalesItem' (or there is no acceptable conversion) 错误C ++ 2679(二进制&#39;&gt;&gt;&#39;:找不到使用类型为&#39;const std :: string&#39;的右侧操作数的运算符(或没有可接受的转换)) - Error C++ 2679 (binary '>>': no operator found which takes a right-hand operand of type 'const std::string' (or there is no acceptable conversion)) 错误 C2679:二进制“&gt;&gt;:未找到采用“GradeType”类型的右侧操作数的运算符 - error C2679: binary ' >> : no operator found which takes a right-hand operand of type 'GradeType' 错误 C2679 二进制“&lt;&lt;”:未找到采用“T”类型右侧操作数的运算符 - Error C2679 binary '<<': no operator found which takes a right-hand operand of type 'T' 错误C2679:二进制&#39;&lt;&lt;&#39;:找不到运算符,该运算符使用类型为&#39;std :: string&#39;的右侧操作数 - error C2679: binary '<<':no operator found which takes a right-hand operand of type 'std::string' 错误C2679的问题:二进制&#39;+ =&#39;:未找到采用类型为&#39;int&#39;的右侧操作数的运算符 - Issue with error C2679: binary '+=': no operator found which takes a right-hand operand of type 'int' 二进制“&lt;&lt;”:未找到采用“c1”类型的右侧操作数的运算符 - binary '<<': no operator found which takes a right-hand operand of type 'c1'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM