我想填写一个std::map使用std::generate_n但不能让它工作.我尝试的是这些方面:
unsigned number_of_pairs{5};
std::map<std::string, std::string> my_map;
auto read_pair_from_input = [](){
std::string key;
std::getline(std::cin, key);
std::string value;
std::getline(std::cin, value);
return std::make_pair(key, value);
};
std::generate_n(my_map.begin(), number_of_pairs, read_pair_from_input);
Run Code Online (Sandbox Code Playgroud)
这给了我很长的错误,如:
In file included from /opt/wandbox/gcc- head/include/c++/8.0.0/algorithm:62:0,
from prog.cc:1:
/opt/wandbox/gcc-head/include/c++/8.0.0/bits/stl_algo.h: In instantiation of '_OIter std::generate_n(_OIter, _Size, _Generator) [with _OIter = std::_Rb_tree_iterator<std::pair<const std::__cxx11::basic_string<char>, std::__cxx11::basic_string<char> > >; _Size = unsigned int; _Generator = main()::<lambda()>]':
prog.cc:18:74: required from here
/opt/wandbox/gcc-head/include/c++/8.0.0/bits/stl_algo.h:4468:11: error: use of deleted function 'std::pair<_T1, _T2>& std::pair<_T1, _T2>::operator= (typename std::conditional<std::__not_<std::__and_<std::is_copy_assignable<_Tp>, std::is_copy_assignable<_T2> > >::value, …Run Code Online (Sandbox Code Playgroud) 我们的团队共享一台MacBook,每个人都会不时使用一个帐户,所以我们都在登录.要提交我们的代码更改,我们使用的是SmartGitHg 4.5(安装的当前Git版本是1.8.3.2).由于这些提交可能会有点混乱,我正在寻找一个以正确名称提交的setup/config解决方案,因为如果我将Git的全局配置中的userdata保留为空,我将自动以"开发人员"的名义提交(即使我在提交/推送时总是被要求提供凭证,这也是我们机器的帐户名称.
所以也许有人知道如何设置它,以便在提交/推/拉时只需要输入凭据.也许使用OSX钥匙串可能是一种方式?
我正在尝试为我的qml应用程序实现键盘快捷键控件.我知道有可能使用Action元素,但我不想要必须使用的菜单和工具栏.这就是我用键盘事件接近这个主题的原因.为此,我需要让执行操作的元素成为焦点.但我的目标是全局快捷控制,所以理论上我需要把所有有问题的元素都集中在一起.我FocusScope在文档中找到了类型,但我不确定这是否是我需要的.这是否意味着嵌套FocusScopes'幻灯片' 的焦点通过最后一个元素' FocusScopes不是手动获取焦点,focus: true因此只有最后一个元素保持焦点?或者在获得焦点的幻灯片上的所有元素都有activeFocus 物业集?
这是正确的方法还是我需要别的东西?
我正在 QML 中开发一个消息对话框窗口的小系统。为此,我使用带有加载器的容器来加载不同的消息(这些消息不仅仅是文本,而是布局的文本和图形符号,因此为每个单独的消息加载 QML 文件)。默认情况下,这些消息窗口具有相同的大小,因此我将大小信息直接存储在容器中。但有些消息可能会更长,因此我正在寻找一种方法来使用height我加载的组件(如果它超过默认值)。在我看来,我的问题可以分为三个部分:
Loader对象访问已加载组件的大小信息?有什么建议么?
我目前正在尝试Go并且遇到上述错误消息.看一下接口,它对float64的实现和测试.
接口:
package interval
import (
"errors"
"fmt"
"math"
)
type Interval interface {
Intersect(Y Interval) (Interval, error) // Intersection of X and Y, error 'nil' when empty
}
type floatInterval struct {
a, b float64
}
func (fi floatInterval) Intersect(Y Interval) (Interval, error) {
tmp := Y.(floatInterval)
a_new, b_new := math.Max(fi.a, tmp.a), math.Min(fi.b, tmp.b)
result := floatInterval{a_new, b_new}
if result.Length() == 0 {
return result, errors.New("Empty interval")
} else {
return result, nil
}
}
Run Code Online (Sandbox Code Playgroud)
测试:
func intersect_test(t *testing.T, …Run Code Online (Sandbox Code Playgroud) 我在使用 CPP REST SDK 的 JSON 类时遇到了问题。我不知道什么时候使用json::value,json::object和json::array。尤其是后两者看起来很像。的用法json::array对我来说也很不直观。最后,我想将 JSON 写入文件或至少写入 stdcout,以便我可以检查它是否正确。
使用 json-spirit 对我来说更容易,但是因为我想稍后发出 REST 请求,所以我想我会省掉字符串/wstring 的疯狂并使用 CPP REST SDK 的 json 类。
我想要实现的是一个像这样的 JSON 文件:
{
"foo-list" : [
{
"bar" : "value1",
"bob" : "value2"
}
]
}
Run Code Online (Sandbox Code Playgroud)
这是我试过的代码:
json::value arr;
int i{0};
for(auto& thing : things)
{
json::value obj;
obj[L"bar"] = json::value::string(thing.first);
obj[L"bob"] = json::value::string(thing.second);
arr[i++] = obj;
}
json::value result;
result[L"foo-list"] = arr;
Run Code Online (Sandbox Code Playgroud)
我真的需要这个额外的计数器变量i吗?显得比较不雅观。使用 json::array/json::object 会让事情变得更好吗?以及如何将我的 JSON …
我已经能够std::vector<char>使用boost和以下代码编码到Base64:
using namespace boost::archive::iterators;
std::string message(binary.begin(), binary.end());
std::stringstream os;
using base64_text = insert_linebreaks<base64_from_binary<transform_width<const char *, 6, 8>>, 72>;
std::copy(
base64_text(message.c_str()),
base64_text(message.c_str() + message.size()),
ostream_iterator<char>(os)
);
return os.str();
Run Code Online (Sandbox Code Playgroud)
我在Stackoverflow上发现了这个.好吧,现在我想向后退一步,放入Base64格式化std::string并最终得到一个std::vector<char>.但我不能适应我的例子来反过来做事.我在网上找到了一些其他的代码,它与Hello World示例很好用,但是当有一个实际更大的Base64,它还包含一些像反斜杠这样的关键字符时,整个事情就崩溃了.
这就是我现在正在做的解码:
using namespace std;
using namespace boost::archive::iterators;
typedef
transform_width<
binary_from_base64<string::const_iterator>, 8, 6
> binary_t;
string dec(binary_t(str.begin()), binary_t(str.end()));
return dec;
Run Code Online (Sandbox Code Playgroud)
当我要创建字符串时,它会在返回之前的最后一行崩溃.你看到它有什么问题吗?
c++ ×2
qml ×2
qt ×2
base64 ×1
boost ×1
c++11 ×1
cpprest-sdk ×1
dictionary ×1
git ×1
go ×1
json ×1
multi-user ×1
qtquick2 ×1