looper@looper-virtual-machine:~/CODE/testcode/Bitset2Vector_then_SHAhash$ g++ -o EXE Bitset2Vector_then_SHAhash.cpp -lssl -lcrypto Bitset2Vector_then_SHAhash.cpp: In function ‘int main()’: Bitset2Vector_then_SHAhash.cpp:51:50: error: conversion from ‘const Eigen::WithFormat<Eigen::Transpose<Eigen::Matrix<double, 1, -1> > >’ to non-scalar type ‘std::string’ {aka ‘std::__cxx11::basic_string<char>’} requested 51 | std::string input = newVec.transpose().format(Eigen::IOFormat(Eigen::FullPrecision, Eigen::DontAlignCols, " ", " ", "", "", "[", "]"));
时间: 2024-04-08 11:29:54 浏览: 203
根据您提供的代码片段和错误信息,我注意到在第51行存在一个错误。错误提示指出您尝试将Eigen库中的WithFormat
类型的对象转换为std::string
类型,但这是不允许的。
要解决这个问题,您可以将format
函数应用于Eigen向量对象newVec.transpose()
,然后将其结果转换为std::string
类型。您可以使用.format()
函数的返回类型std::stringstream
来实现这一点,并将其转换为std::string
。
以下是一个修改后的代码示例:
#include <iostream>
#include <sstream>
#include <Eigen/Dense>
int main() {
Eigen::MatrixXd newVec(1, 5);
newVec << 1, 2, 3, 4, 5;
std::stringstream ss;
ss << newVec.transpose().format(Eigen::IOFormat(Eigen::FullPrecision, Eigen::DontAlignCols, " ", " ", "", "", "[", "]"));
std::string input = ss.str();
std::cout << "Input: " << input << std::endl;
// 其他代码...
return 0;
}
请注意,上述代码假设您已正确包含了Eigen库的头文件,并且通过命令行参数-lssl -lcrypto
指定了链接SSL和Crypto库。
希望这可以帮助您解决问题!如果还有其他问题,请随时提问。
相关推荐





