草庐IT

value_variable

全部标签

c++ - C/C++ sizeof 运算符 : Why does sizeof( 'a' ) return different values?

这个问题在这里已经有了答案:关闭10年前。PossibleDuplicate:Sizeofcharacter('a')inC/C++我是C的初学者,对此感到困惑。C:我尝试使用“%zu”修饰符在C中打印sizeof('a'),它打印出值4。C++:在C++中使用cout打印sizeof('a')和printf(使用上述格式)都打印出值1。我认为正确的值应该是1,因为'a'将被视为字符。为什么它不在C中返回4?两种语言的操作大小是否不同?如果是这样,有什么区别,为什么它会返回不同的值?我在这两种情况下都使用了gcc编译器。

c++ - 根据 value_type 调用适当的构造函数 : integer or float

我有一个函数,它使用均匀分布将最小值和最大值之间的随机值填充到容器中。#include#include#include#includetemplatevoiduniform_random(TContainer&container,consttypenameTContainer::value_typemin,consttypenameTContainer::value_typemax){std::random_devicerd;std::mt19937gen(rd());//Belowlinedoesnotworkwithintegerscontainerstd::uniform_rea

c++ - 如何在 while 循环中计算 "std::cin>>value"?

目前正在自学C++Primer5th。这里有一些我不确定的东西。(我在F.A.Q上找不到确切的相关问题)。考虑这个while循环:while(std::cin>>value){...}\\valueherewasdefinedasint.课本上说:Thatexpressionreadsthenextnumberfromthestandardinputandstoresthatnumberinvalue.Theinputoperator(§1.2,p.8)returnsitsleftoperand,whichinthiscaseisstd::cin.Thiscondition,there

c++ - 错误 C2106 : '=' : left operand must be l-value

查看有关错误C2106的其他问题,我仍然不知道我的代码有什么问题。编译时出现以下错误:c:\driver.cpp(99):errorC2106:'=':leftoperandmustbel-valuec:\driver.cpp(169):errorC2106:'=':leftoperandmustbel-value代码行如下:payroll.at(i)=NULL;//Line99payroll.at(count++)=ePtr;//Line169我不明白为什么会抛出这个错误。在这个项目中,我将我的driver.cpp从员工对象指针数组更改为我制作的自定义Vector模板。我声明Vect

c++ - 错误 : Variable length array of Non-POD element type 'string'

在开始之前,我必须首先声明,我已经研究过针对此错误的可能解决方案。不幸的是,它们都与不使用数组有关,这是我项目的要求。另外,我目前正在学习CS入门类(class),所以我的经验几乎没有。数组的用途是从文件中收集名称。因此,为了初始化数组,我计算了名称的数量并将其用作大小。问题是标题中所述的错误,但我仍然使用一维数组时看不到解决方法。主要.cpp#include#include#include#include#include#include"HomeworkGradeAnalysis.h"usingnamespacestd;intmain(){ifstreaminfile;ofstrea

c++ - std::condition_variable::wait_until 相对于 std::this_thread::sleep_for 有什么优势吗?

在时间等待场景中:oursoftwareworksinthebackground,andsynchronizesdatawiththeserverinevery20-30minutes.我想用std::this_thread::sleep_for但我的上级强烈反对任何形式的sleep功能。他推荐std::condition_variable::wait_until(lock,timeout-time,pred)不知道在这种情况下sleep_for有什么缺点吗? 最佳答案 正如评论中已经指出的那样,这仅取决于您的用例。两者之间的主要区

c++ - Ada 到 C++ : Pass an unsigned 64-bit value

我需要将2条数据从Ada程序传递给一些C++代码进行处理。数据-双倍。时间-无符号64位。我能够使用Long_Float(在C++中为double)和Integer(在C++中为int,但显然不是64位)在Ada中创建一个与我的C++方法一起工作的过程。我使用了以下代码(代码不在我身上,所以语法可能略有偏差):proceduresend_data(this:inhidden_ptr;data:inLong_Float;time:inInteger);pragmaimport(CPP,send_data,"MyClass::sendData");现在它正在运行,我正在尝试将时间扩展到完整

c++ - 什么时候需要在 Ruby C 扩展中声明 volatile VALUE?

我找不到很多文档来说明何时适合在Ruby扩展中将VALUE声明为volatile以避免对正在使用的对象进行过早的垃圾回收。这是我到目前为止学到的东西。任何人都可以填空吗?当volatile不需要使用时:在C++对象成员中(因为它们永远不会在堆栈上?)在不调用RubyAPI的C/C++方法中(因为GC在调用RubyAPI之前不会打开)当volatile确实需要使用在调用任何RubyALLOC或malloc宏/函数的C/C++方法中(因为当内存高度碎片化时这些会触发GC)在调用任何Ruby函数的C/C++方法中(例如,rb_funcall、rb_ary_new等)其他避免GC的方法标记正在

c++ - 统一和值(value)初始化

这个问题在这里已经有了答案:g++4.9rejectsvalidaggregateinitializationinC++14(1个回答)关闭7年前。我尝试对构造函数使用值初始化的成员使用值初始化(我不知道我是否真的使用了好的术语......)所以...当我定义:structA{inta_;};我可以使用:Aa{5};assert(m.a_==5);但是,如果我想使用成员大括号初始化器和初始化列表构造器structB{intb_{1};};这无法编译(c++14:http://ideone.com/MQ1FMU):Bb{2};这里是错误:prog.cpp:19:7:error:nomat

c++ - std::condition_variable::wait with predicate

在std::condition_variable的文档中,有一个以谓词函数作为参数的wait()重载。该函数将等到谓词函数为真的第一个wake_up。在documentation据说这等同于:while(!pred()){wait(lock);}还有:Thisoverloadmaybeusedtoignorespuriousawakeningswhilewaitingforaspecificconditiontobecometrue.Notethatbeforeentertothismethodlockmustbeacquired,afterwait(lock)exitsitisals