【发布时间】:2020-07-12 17:33:23
【问题描述】:
我在课堂作业方面遇到问题。我们提供了一个网站,该网站在后端有几张各种动物的图片。我们应该能够输入动物的名字,下面会出现与动物名字相对应的图片。这一切都在 search.h 文件和 C++ 中。
教授在讲座中很快就讨论了这个话题,没有太多解释如何继续。我一直在寻找从矢量获取数据的可能解决方案,并尝试使用地图操作但无济于事。我对 C++ 不是很熟悉。我将在下面提供代码。接下来我应该采取什么步骤?
#include <server.h>
ucm::json big5;
std::vector<std::string> lions = {"lion-1.jpeg", "lion-2.jpeg", "lion-3.jpeg", "lion-4.jpeg"};
std::vector<std::string> rhinos = {"rhino-1.jpeg", "rhino-2.jpeg", "rhino-3.jpeg", "rhino-4.jpeg"};
std::vector<std::string> buffalos = {"buffalo-1.jpeg", "buffalo-2.jpeg", "buffalo-3.jpeg", "buffalo-4.jpeg"};
std::vector<std::string> elephants = {"elephant-1.jpeg", "elephant-2.jpeg", "elephant-3.jpeg", "elephant-4.jpeg"};
std::vector<std::string> leopards = {"leopard-1.jpeg", "leopard-2.jpeg", "leopard-3.jpeg", "leopard-4.jpeg"};
void init(){
big5["lion"] = lions;
big5["rhino"] = rhinos;
big5["buffalo"] = buffalos;
big5["elephant"] = elephants;
big5["leopard"] = leopards;
}
ucm::json search(std::string key){
// Provide your code here
// This function should return a specific animal category, specified by key
// The function should return an appropriate message if the key is not found
}
ucm::json getAll(){
// This should return all the data we have
ucm::json temp;
temp["lion"] = big5["lion"];
return big5;
}
我再次要求的不是解决方案,而是一个起点。
【问题讨论】:
-
什么是
ucm::json?顺便说一下std::string key应该是const std::string& key。 -
我相信这就是我访问服务器的原因。 ucm 是我学校的名称。
-
如果您有权访问
ucm::json文档,您需要检查您是否可以迭代这样的对象。您需要有关该对象允许您执行哪些操作的信息。 -
你有
ucm::json来源的链接吗? -
哦,我明白了,我不相信,不,我必须在本地连接到服务器