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). Luckily, boost::filesystem::path
provides a function that returns a string!