【发布时间】:2021-01-25 01:45:49
【问题描述】:
我正在使用 boost 库来拆分字符串,但出现错误
'<function-style-cast>': cannot convert from 'initializer list' to 'SeqT'
位于 CmdInst.hpp 的第 29 行(旁边也会有注释)
main.cpp
#include <iostream>
#include "CmdInst.hpp"
int main() {
auto inst = cmd::cmdInst();
inst.start();
}
CmdInst.hpp
#pragma once
#include <string>
#include <iostream>
#include <boost/algorithm/string.hpp>
#include <vector>
namespace cmd {
class cmdInst {
private:
std::string loc;
public:
cmdInst(std::string curloc = "") {
loc = curloc;
}
void start() {
while (true) {
std::string cmd;
std::cout << "&" << loc << ">";
std::cin >> cmd;
boost::split(cmd, cmd, boost::is_any_of(" "));
if (std::to_string(cmd[0]) == "cd") {
if (std::to_string(cmd[1]) == "..") {
std::vector<std::string> tloc;
boost::split(tloc,loc,boost::is_any_of("/")); //------error here------
std::string tmp("");
for (size_t i = 0; i < tloc.size() - 1; i++) {
tmp += tloc[i]+"/";
}
loc = tmp;
}
}
else {
loc += "/" + cmd[1];
}
std::cout << "\n";
}
}
};
}
错误实际上来自从 split 函数调用的 boost 库文件夹,但这是我“实际上”导致错误的行
inline SeqT copy_range( const Range& r )
{
return SeqT( boost::begin( r ), boost::end( r ) ); //error on this line
}
【问题讨论】:
标签: c++ visual-studio visual-c++ boost visual-studio-2019