Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/164.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++ C2039 C2228和x27;获取值或';:不是';网络::基本字符串视图<;char,std::char_traits<;char>&燃气轮机';_C++_Boost_Visual Studio 2015_Uri - Fatal编程技术网

C++ C2039 C2228和x27;获取值或';:不是';网络::基本字符串视图<;char,std::char_traits<;char>&燃气轮机';

C++ C2039 C2228和x27;获取值或';:不是';网络::基本字符串视图<;char,std::char_traits<;char>&燃气轮机';,c++,boost,visual-studio-2015,uri,C++,Boost,Visual Studio 2015,Uri,我试图编译一段代码,但收到以下错误: error C2039: 'get_value_or': is not a member of 'network::basic_string_view<char,std::char_traits<char>>' note: see declaration of 'network::basic_string_view<char,std::char_traits<char>>' error C2228: left of '.get_va

我试图编译一段代码,但收到以下错误:

error C2039: 'get_value_or': is not a member of 'network::basic_string_view<char,std::char_traits<char>>' note: see declaration of 'network::basic_string_view<char,std::char_traits<char>>' error C2228: left of '.get_value_or' must have class/struct/union 错误C2039:“获取\u值\u或”:不是“网络::基本\u字符串\u视图”的成员 注意:请参见“网络::基本\u字符串\u视图”的声明 错误C2228:“.get\u value\u或”的左侧必须具有类/结构/联合
#包括“StdInc.h”
#包括
#包括
#包括
boost::string_ref scheme=serviceUri.scheme().get_value_或(“part1”);
如果(方案==“第1部分”)
{
boost::string_ref hostname=serviceUri.host().get_value_或(“localhost”);
int port=serviceUri.port().get_value_或(2800);
我正在使用Visual Basic 2015 Update 3和您使用的Boost 1.57.0

然而,4年前他们有(另一个):

将返回可选字符串视图对象的访问器替换为两个单独的函数

更糟糕的是,它们仍然返回一个手动滚动的
string\u视图
,而不是标准视图

另外,他们版本的
network::optional
从未有过
get\u value\u或
。事实上
get\u value\u或
仅是Boost,支持(标准)
value\u或

结论 使用
has\u scheme()
访问器查看是否存在方案。您可以选择:

#include <boost/utility/string_ref.hpp>
#include <network/uri/uri.hpp>
#include <network/string_view.hpp>
#include <optional>

int main() {
    network::uri serviceUri("http://cpp-netlib.org/");

    network::optional<network::string_view> scheme, hostname, port;

    if (serviceUri.has_scheme())
        scheme = serviceUri.scheme();
    if (serviceUri.has_host())
        hostname = serviceUri.host();
    if (serviceUri.has_port())
        port = serviceUri.port();

    scheme   = scheme.value_or("part1");
    hostname = hostname.value_or("localhost");
    port     = scheme.value_or("2800");
}

根据(我能找到的最好的)
network::string\u view
没有名为
get\u value\u或
的方法,所以我想问题是你为什么认为它应该有。我想你是如何获得这段代码的,以及你对它做了哪些修改的一些历史是需要的。@john我在搜索互联网后得出了相同的结论,但我不知道有什么改动这是我4年前存档的游戏服务器客户端代码,目前我想尝试对其进行排序。我是一个彻头彻尾的傻瓜,所以我很抱歉让更多有经验的人挠头。这段代码当时声称已准备好构建。我已经做了0次修改除了更改最后2个#include以强制VS查找文件之外,对代码进行修改。
头文件属于哪个库?或者是您自己编写的(是您使用完整路径来#包含它们)?它们当然不是Boost的一部分。请查看
网络::basic_string_view
类中实际声明的方法,以查看实际可用的方法。@9445a4dcb9我认为您可能刚引入了错误的库。我环顾了一下,看不到任何证据表明我引用的库能够进行编译ile您拥有的代码。@9445a4dcb9但其意图已经足够清楚。如果指定的URL没有方案,请使用“part1”,如果没有主机,请使用“localhost”,如果没有端口,请使用2800。也许您可以将代码改编为您拥有的库。
#include <boost/utility/string_ref.hpp>
#include <network/uri/uri.hpp>
#include <network/string_view.hpp>
#include <optional>

int main() {
    network::uri serviceUri("http://cpp-netlib.org/");

    network::optional<network::string_view> scheme, hostname, port;

    if (serviceUri.has_scheme())
        scheme = serviceUri.scheme();
    if (serviceUri.has_host())
        hostname = serviceUri.host();
    if (serviceUri.has_port())
        port = serviceUri.port();

    scheme   = scheme.value_or("part1");
    hostname = hostname.value_or("localhost");
    port     = scheme.value_or("2800");
}
#include <network/uri/uri.hpp>
#include <optional>

int main() {
    network::uri serviceUri("http://cpp-netlib.org/");

    std::string const scheme = serviceUri.has_scheme()
        ?  serviceUri.scheme().to_string()
        : "part1";

    std::string const host = serviceUri.has_host()
        ?  serviceUri.host().to_string()
        : "localhost";

    std::string const port = serviceUri.has_port()
        ?  serviceUri.port().to_string()
        : "2800";
}