作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在构建一个用于通过 LAN 发送文件的客户端/服务器应用程序。这是服务器应用程序,当我要获取文件名时,我的代码出现以下错误。
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
提供了一个返回字符串的函数!
关于C++ Boost - 没有找到接受类型为 'boost::filesystem::path' 的右手操作数的运算符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17637021/
我为 UE4 编写了一个插件,用于在 UE4 关卡中匹配和生成静态网格物体 Actors。 该插件从每个脚本从 Softimage XSI 导出的文本文件(缩放、旋转、变换)中读取坐标。一切正常。但不
我是一名优秀的程序员,十分优秀!