2013-07-14 2 views
1

저는 LAN을 통해 파일을 전송하는 클라이언트/서버 응용 프로그램을 구축하고 있습니다. 이것은 끊김없는 응용 프로그램이며 파일 이름을 가져올 때 코드에 다음과 같은 오류가 발생합니다.C++ Boost - '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 
    } 
} 

// 코드

+0

filename = boost :: filesystem :: path (filename) .filename(); 파일 이름()도 경로가 아닐까요? 당신이 그것을 문자열로 변환 할 수 있는지보십시오. – alexbuisson

답변

3

그냥이 라인 변경 : 이것에

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

: 기본적으로

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

컴파일러가 std::string 어떤 할당 연산자를 정의하지 않음을 말하고있다을 매개 변수로 boost::filesystem::path을 사용합니다 (또는 대화가 없음). 이온은 할당 연산자의 매개 변수로 사용할 수있는 유형을 제공합니다). 다행히도 boost::filesystem::path은 문자열을 반환하는 함수를 제공합니다!

관련 문제