C++ Boost - 未找到采用类型 'boost::filesystem::path' 的右操作数的运算符
C++ Boost - no operator found which takes a right-hand operand of type 'boost::filesystem::path'
我正在构建一个客户端/服务器应用程序,用于通过局域网发送文件。这是服务器应用程序,当我要获取文件名时,我的代码出现了以下错误。
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
}
}
//代码
只需更改此行:
filename = boost::filesystem::path(filename).filename();
到此:
filename = boost::filesystem::path(filename).filename().string();
基本上,编译器告诉您,std::string
没有定义任何将boost::filesystem::path
作为参数的赋值运算符(或者它无法进行转换,从而提供可以用作赋值运算符参数的类型)。幸运的是,boost::filesystem::path
提供了一个返回字符串的函数!
相关文章:
- [LLVM-9 clang-9 OSX]: std::filesystem::path unrecognized
- 使用std :: filesystem :: path中的double
- c++ std::bad_alloc on std::filesystem::path append
- 更改狭窄的字符串编码或丢失std :: filesystem :: path :: imbue
- 如果P从root路径开始,为什么STD :: filesystem :: path :: append替换当前路径
- 错误:无法通过'...'传递非平凡可复制类型的对象'class boost::filesystem::path'
- boost::filesystem::path.parent_path() and whitespace
- /usr/include/boost/filesystem/path.hpp:307:未定义对'boost::files
- 使用std::filesystem::path在分隔符类型之间进行转换
- 在windows上将filesystem::path转换为char*
- 为什么BOOST :: fileSystem :: path and std :: filesystem ::路径含量含
- boost::filesystem::d irectory_interatory i(path) 在 Qt Creato
- boost::filesystem::remove_all(path)如何工作
- 无法解析类型 "boost::filesystem::path"
- boost::filesystem::path vs boost::filesystem::wpath
- boost::filesystem::path to QByteArray
- C++ Boost - 未找到采用类型 'boost::filesystem::path' 的右操作数的运算符
- boost::filesystem::path::string()输出的奇怪行为
- boost::filesystem::path导致内存差异
- Boost::filesystem::path::imbue失败,默认的std::locale()