草庐IT

int_void

全部标签

java - "|"中的 "int style = SWT.APPLICATION_MODAL | SWT.OK;"有什么作用(以及如何用谷歌搜索它)?

我无法搜索|在谷歌。如果您在试图解释的软件源代码中发现了它,但您不知道它的作用,也无法向其他人寻求帮助,您将如何找到它的作用? 最佳答案 在这种情况下,管道运算符的意思是“同时使用SWT.APPLICATION_MODAL和SWT.OK作为我的弹出框的选项/标志。”这是一个非常常用的带有位域配置标识符的习惯用法,尤其是。在SWT或Win32等窗口系统中。工作原理竖线(|)运算符是按位或运算符,即计算两个二进制整数值的或运算。如果查看APPLICATION_MODAL和OK的定义位置,您会发现它们是这样的:...SWT.OK=1,//

c++ - 如何将 std::wstring 转换为数字类型(int、long、float)?

将std::wstring转换为数字类型(例如int、long、float或double)的最佳方法是什么? 最佳答案 C++0x引入了followingfunctions在:intstoi(constwstring&str,size_t*idx=0,intbase=10);longstol(constwstring&str,size_t*idx=0,intbase=10);unsignedlongstoul(constwstring&str,size_t*idx=0,intbase=10);longlongstoll(constw

c++ - 错误 : no matching function for call to ‘std::vector<std::__cxx11::basic_string<char>>::push_back(int&)’

我是C++的新手。当我运行我的代码时出现此错误:(BigSorting.cpp:Infunction‘intmain(int,constchar**)’:BigSorting.cpp:13:22:error:nomatchingfunctionforcallto‘std::vector>::push_back(int&)’v.push_back(m);^Infileincludedfrom/usr/include/c++/8.1.1/vector:64,fromBigSorting.cpp:2:/usr/include/c++/8.1.1/bits/stl_vector.h:1074:

c++ - double 到 unsigned int/char

我读了here,即:根据C99§6.3.1.4脚注50:Theremainderingoperationperformedwhenavalueofintegertypeisconvertedtounsignedtypeneednotbeperformedwhenavalueofrealfloatingtypeisconvertedtounsignedtype.Thus,therangeofportablerealfloatingvaluesis(−1,Utype_MAX+1).现在,我对以下之间的细微差别感兴趣(这次是针对C++03!):doubled1=257;doubled2=-2

c++ - 如何在 C++ 中将 const int 设置为最大值?

我有一个静态常量成员,想将它设置为最大整数。我正在尝试以下操作:conststaticintMY_VALUE=std::numeric_limits::max();但是得到如下错误:error:in-classinitializerforstaticdatamemberisnotaconstantexpression有什么解决办法吗?函数如何不返回常量表达式?编辑:添加-std=c++11解决了这个问题。我的室友告诉我,编译器(C++11之前的版本)不够聪明,无法决定std::numeric_limits::max()不会改变任何其他内容,因此不被视为常量。这可能是导致此错误的原因吗?

c++ - 禁止在函数调用中隐式转换为 int

这个问题在这里已经有了答案:HowdoIavoidimplicitconversionsonnon-constructingfunctions?(8个答案)关闭5年前。我有一个函数:voidfoo(intn){std::cout可以使用不同的参数调用,可以是char、double、float等:foo(123);//1foo('c');//2foo(0.2);//3foo(0.2f);//4//......但我只想允许int参数(文字或变量),因此上面的2,3,4,...是非法的。我目前的解决方案是删除那些重载:voidfoo(char)=delete;voidfoo(float)=d

c++ - 如果 count() 是 constexpr 函数,为什么 std::array<int, count()> 不能编译?

这个问题在这里已经有了答案:constexprnotworkingifthefunctionisdeclaredinsideclassscope(3个回答)3年前关闭。为什么下面的C++代码不能用VC2017编译?structFixedMatchResults{staticconstexprstd::size_tcount(){return20;};std::arrayresults;};错误是:errorC2975:'_Size':invalidtemplateargumentfor'std::array',expectedcompile-timeconstantexpression

c++ - 诸如 `msg(long)` 与候选 `msg(int32_t)` 和 `msg(int64_t)` 等函数的模糊重载

注意:这与Determinenumberofbitsinintegraltypeatcompiletime非常相似,但是这是一个非常简化的版本,所有内容都包含在一个.cpp中编辑:添加了一个解决方案-尽管给出了(并接受)了正确的解释,但我找到了一种通用的解决问题的方法。问题问题在于像这样的函数msg(int32_t);msg(int64_t);像这样的电话longlongmyLong=6;msg(myLong);//Won'tcompileongcc(4.6.3),callisambiguous这在MSVC上编译。谁能解释为什么这在gcc上失败(我假设这可能与gcc通常严格符合标准这一

c++ - 如何在 C++11 中将 u32string 转换为 int?

我们如何在C++11中将u32string转换为int?另外,我应该使用什么方法将此类字符串的一部分转换为int-让开始和结束迭代器可用?我试过:u32stringtest=U"14";cout但它抛出:candidatefunctionnotviable:noknownconversionfrom'constchar32_t*'to'constchar*'for1stargumentexternintatoi(__constchar*__nptr) 最佳答案 #include//wstring_convert#include//c

c++ - 是什么让 enum -> int 比 enum -> unsigned 转换更好?

在下面的代码中,选择了重载f(int)而不是f(unsigned)。使用clang3.0和gcc4.8测试。enumE{};Ef(int);intf(unsigned);Ee=f(E(0));我对标准的阅读使我认为enum->int和enum->unsigned是相同的标准转换序列,它们都只包含一个整数转换。[conv.integral]Anrvalueofanenumerationtypecanbeconvertedtoanrvalueofanintegertype.根据[over.best.ics],仅包含整数转换的标准转换序列的等级是'Conversion'。[over.ics.