小编Hum*_*ird的帖子

Flutter 应用程序中 firebase 数据库上的 ValueEventListener

我正在学习 Flutter 中的 android 应用程序开发。我从颤振聊天应用程序示例开始。在启用数据同步部分,解释了如何使用 Firebase 数据库,如下所示。

final DBreference = FirebaseDatabase.instance.reference().child('messages');

另外,push()set()方法都工作正常。

当我尝试使用ValueEventListener. 在DBreference上面创建具有类似于没有方法addListenerForSingleValueEventaddValueEventListener

我的主要目标是检索 SO 答案中解释的 child 值 Retrieving child value -firebase-Checking if a specific value exists in the firebase database

我得到 undefined class ValueEventListener
如果我创建一个新的ValueEventListener,我尝试通过导入

import 'com.google.firebase.database.ValueEventListener';

我也无法导入此路径。相同的错误addListenerForSingleValueEventaddValueEventListener

我正在使用 android studio 3.1

android firebase firebase-realtime-database flutter

6
推荐指数
1
解决办法
3975
查看次数

模板类的友元函数中的链接错误

我有模板类节点,为了遵循复制和交换习惯用法,我尝试编写swap属于friend类的函数Node

我的代码是:

Node.h

#ifndef NODE_H
#define NODE_H

#include<memory>
template<typename type>
class Node
{
    type data_;
    std::unique_ptr<Node> next_;
public:
    Node(type data);
    Node(const Node& other);
    Node& operator=(Node other);
    friend void swap(Node& lhs, Node& rhs);
};

#include "Node.tpp"
#endif
Run Code Online (Sandbox Code Playgroud)

Node.tpp

template<typename type>
Node<type>::Node(type data):data_(data),next_(nullptr){
}

template<typename type>
Node<type>::Node(const Node& other)
{
    data_ = other.data_;
    next_ = nullptr;
    if(other.next_ != nullptr)
    {
        next_.reset(new Node(other.next_->data_));
    }
}
template<typename type>
void swap(Node<type>& lhs, Node<type>& rhs)
{
    using std::swap; …
Run Code Online (Sandbox Code Playgroud)

c++ copy-and-swap

5
推荐指数
1
解决办法
403
查看次数

卷曲与CPPREST

我正在尝试使用CPPREST http_client访问URL:

http://www.20min.ch/rss/rss.tmpl?type=channel&get=68

我收到了URL重定向的响应代码302.

但是当我尝试使用CURL访问相同的URL时,我收到了CURLE_OK.

以下是2段代码:

使用CURL:

CURL *curl;
CURLcode res;
curl_global_init(CURL_GLOBAL_ALL);
curl = curl_easy_init();
if(curl){
    curl_easy_setopt(curl, CURLOPT_URL, "http://www.20min.ch/rss/rss.tmpl?type=channel&get=68");
    res = curl_easy_perform(curl);
    if(res != CURLE_OK)     {
        cout<<"failed";
    }
    else  {
        cout<<"success";
    }
    curl_easy_cleanup(curl);
}
curl_global_cleanup();
Run Code Online (Sandbox Code Playgroud)

输出是:成功

使用CPPREST:

std::string url_= "http://www.20min.ch/rss/rss.tmpl?type=channel&get=68";
try
{
     http_client client1(U(url_));
     uri_builder builder1(U(""));
     client1.request(methods::GET, builder1.to_string()).then([=](http_response response)
     {
        cout<<"Response code is : "<<response.status_code();
     });
}
catch(std::exception& e)
{
    cout<<"response :"<<e.what();
}
Run Code Online (Sandbox Code Playgroud)

输出是:: Response代码是:302

我不明白为什么两个库对于相同的URL表现不同?

更新:

我也尝试过:

http_client client1(utility::conversions::to_string_t(url_));
Run Code Online (Sandbox Code Playgroud)

http_client client1(U("http://www.20min.ch/rss/rss.tmpl?type=channel&get=68"));
Run Code Online (Sandbox Code Playgroud)

http_client client1(U("http://www.20min.ch/"));
Run Code Online (Sandbox Code Playgroud)

但是cpp休息的反应是相同的302.[用于交叉检查bing的例子

工作正常]

更新2: …

c++ libcurl casablanca

4
推荐指数
1
解决办法
3441
查看次数