Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/127.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/azure/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 让log4cxx与ostream一起快乐<&书信电报;操作人员_C++_Ostream_Log4cxx - Fatal编程技术网

C++ 让log4cxx与ostream一起快乐<&书信电报;操作人员

C++ 让log4cxx与ostream一起快乐<&书信电报;操作人员,c++,ostream,log4cxx,C++,Ostream,Log4cxx,看看这个,我也在尝试组合一个ostream,你在哪里调用这个函数?这个重载的确切位置(什么名称空间)?我们需要一个MCVE向量p;一个示例调用看起来很简单:LOG4CXX_TRACE(logger,“ack()”将一个小示例程序粘贴到问题中以再现错误。这仍然不够。添加命名空间{}我的ostream运算符周围的块会导致此代码正确编译和工作。我在其他源文件中遇到的问题肯定会导致名称空间混乱。我将致力于将此代码分离到它自己的文件中。我将报告我的结果。 ostream& operator<

看看这个,我也在尝试组合一个ostream,你在哪里调用这个函数?这个重载的确切位置(什么名称空间)?我们需要一个MCVE向量p;一个示例调用看起来很简单:LOG4CXX_TRACE(logger,“ack()”将一个小示例程序粘贴到问题中以再现错误。这仍然不够。添加命名空间{}我的ostream运算符周围的块会导致此代码正确编译和工作。我在其他源文件中遇到的问题肯定会导致名称空间混乱。我将致力于将此代码分离到它自己的文件中。我将报告我的结果。
ostream& operator<<(ostream& os, const vector<uint8_t>& bs)
{
    ios_base::fmtflags oldFlags = os.flags();
    streamsize oldPrec = os.precision();
    char oldFill = os.fill();

    int s = bs.size();
    os << setfill('0') << uppercase << hex;
    for (int i = 0; i < s; ++i) {
        os << "0x" << setw(2) << (int)bs[i] << ' ';
    }

    os.flags(oldFlags);
    os.precision(oldPrec);
    os.fill(oldFill);

    return os;
}
Compiling StationControllertest.cpp... In file included from /usr/include/log4cxx/logger.h:32:0,
                 from ./Configuration.h:15,
                 from StationController.h:4,
                 from StationControllertest.cpp:14:
/usr/include/log4cxx/helpers/messagebuffer.h: In function ‘std::basic_ostream<char>& log4cxx::helpers::operator<<(log4cxx::helpers::CharMessageBuffer&, const V&) [with V = std::vector<unsigned char>]’:
StationControllertest.cpp:474:5:   instantiated from here
/usr/include/log4cxx/helpers/messagebuffer.h:190:47: error: cannot bind ‘std::basic_ostream<char>’ lvalue to ‘std::basic_ostream<char>&&’
/usr/include/c++/4.6/ostream:581:5: error:   initializing argument 1 of ‘std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&&, const _Tp&) [with _CharT = char, _Traits = std::char_traits<char>, _Tp = std::vector<unsigned char>]’
makefile:120: recipe for target 'StationControllertest.o' failed
make: *** [StationControllertest.o] Error 1
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <vector>
#include <stdint.h>
#include <log4cxx/logger.h>
#include <log4cxx/propertyconfigurator.h>

using namespace std;
using namespace log4cxx;
using namespace log4cxx::helpers;

static LoggerPtr logger(Logger::getLogger("log4test"));


ostream& operator<<(ostream& os, const vector<uint8_t>& bs)
{
    ios_base::fmtflags oldFlags = os.flags();
    streamsize oldPrec = os.precision();
    char oldFill = os.fill();

    int s = bs.size();
    os << setfill('0') << uppercase << hex;
    for (int i = 0; i < s; ++i) {
        os << "0x" << setw(2) << (int)bs[i] << ' ';
    }

    os.flags(oldFlags);
    os.precision(oldPrec);
    os.fill(oldFill);

    return os;
}


int main(int argc, char* argv[])
{
    PropertyConfigurator::configure("Log4cxxConfig.cfg");

    vector<uint8_t> v = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a };

    cout << v << endl;
    LOG4CXX_INFO(logger, v);
}