草庐IT

default-watch-cache-size

全部标签

c++ - 变长数组 : How to create a buffer with variable size in C++

我目前正在编写一个移动平均线类。目标是在创建Running_Average类的新对象时能够将缓冲区大小指定为构造函数的一部分。#include#include"Complex.h"#include#include#include#includeusingnamespacestd;classRunning_Average{public:doublesum=0;doubleaverage=0;inti;doubleAverage(void);//MemberfunctionsdeclarationvoidAddSample(double);Running_Average(int);};Ru

c++ - 根据 size() 排序 vector

我有一个像vector>v(points);这样的二维vector其中坐标类是:classcoordinate{public:intx;inty;coordinate(){x=0;y=0;}};积分是20。如何基于v[i].size()对单个vectorv[i]进行排序,即基于插入v[i]的坐标对象的数量。??? 最佳答案 1)创建一个根据大小比较两个vector的函数:boolless_vectors(constvector&a,constvector&b){returna.size()2)用它排序sort(v.begin(),v

c++ - 从 std::array 等获取 size_type 的惯用方法

由thisquestion触发,我想出了以下代码(在我的回答中是boost::array,但同样适用于std::array):template::size_typesize>voidDataTransform(std::arraydata){}我对::size_type一点都不满意.我必须以一定的大小进行实例化,才能知道size_type.对于std::array我本可以使用size_t,那么一般情况呢?如果size_type怎么办不是size_t?或者更一般的(即不适用于std::array)如果size_type怎么办?不同的尺寸是不同的(愚蠢但可能)?我知道这个问题相当学术,有很

c++ - 在哪里可以找到 C++ STL 中 vector 的 size_type 定义?

将vector的size()函数的结果转换为unsignedint似乎是安全的。不过,我怎么能确定呢?我的文档不清楚size_type是如何定义的。 最佳答案 不要假定容器大小的类型(或在其中键入的任何其他内容)。今天?目前最好的解决方案是使用:std::vector::size_type其中T是您的类型。例如:std::vector::size_typei;std::vector::size_typej;std::vector>::size_typek;(使用typedef可以帮助使其更好地阅读)对于迭代器和“内部”STL容器中的

c++ - 错误 : initializer fails to determine size of ‘K’

我在行中收到错误“初始化器无法确定‘K’的大小”intK[]=newint[Vertices->total];如何解决? 最佳答案 改变intK[]=newint[Vertices->total];到int*K=newint[Vertices->total];第一个是Java创建数组的方法,其中K是对整数数组的引用。但是在C++中,我们需要让K成为一个指向整数类型的指针。 关于c++-错误:initializerfailstodeterminesizeof‘K’,我们在StackOver

c++ - 与零长度参数一起使用的 memset : ignore or watch out?

在链接动态库时,我无法找到有关以下警告的任何信息:Infunction`MyClass::myfunc()':MyClass.cpp:(.text+0x14e4):warning:memsetusedwithconstantzerolengthparameter;thiscouldbeduetotransposedparameters这是myfunc的摘录:voidMyClass::myfunc(){vector::const_iteratorit;for(it=m_vars.begin();it!=m_vars.end();++it){if((*it)->recordme){MyRe

XCode : Where is the default directory? 上的 C++ ifstream

好的,这是我第一次在Xcode中编写C++代码(我已经习惯了ObjC),现在我已经开始在我的大学学习编程类(class)。我正在尝试打开一个文件(硬编码或来自控制台中的用户输入),但无论我尝试什么,它都说文件无法打开(通过错误检查)我假设这是因为我拥有的test.txt文件不在假定的根目录中,所以如果是这样,那么根目录是什么?到目前为止,这是我的代码://includefiles#include#include#includeusingnamespacestd;//GlobalVariablesshortinputPicture[512][512];shortoutputPicture

Error: Cannot install in Homebrew on ARM processor in Intel default prefix (/usr/local)

Error:CannotinstallinHomebrewonARMprocessorinInteldefaultprefix(/usr/local)错误原因分析解决方案错误原因分析在使用brewinstall命令安装软件包时,出现如上错误。这个错误信息通常出现在使用M1/M2芯片(ARM架构)的Mac上,是因为尝试在Intel架构的默认前缀/usr/local上安装Homebrew时。Homebrew建议在M1/M2芯片上使用不同的前缀目录/opt/homebrew来安装,以确保与M1/M2芯片兼容的二进制文件被正确安装。这是为了避免架构不匹配的问题。解决方案为了解决这个问题,需要重新在/o

c++ - 使用 std::array::size 实例化 std::array 时出错

示例代码test.cpp#include#includeintmain(){//OKconststd::arrayarray_int={42,1337};std::arrayarray_float_ok;//Errorconststd::arrayarray_string={"foo","bar"};std::arrayarray_float_error;return0;}使用g++4.8.4(Ubuntu14.04)编译g++-Wall-std=c++0xtest.cpp-otest给出如下错误信息test.cpp:Infunction‘intmain()’:test.cpp:14:

c++ - 如何在 C++ 中创建一个 "default"流插入运算符?

我有一个类似于boost::any的类,因为它是一个模板化的容器类。我想要一种将包含的值写入字符串的方法。但是,如果包含的类型不提供流插入运算符,我希望我的方法返回一些默认字符串而不是编译失败。下面是我最接近的,应该清楚我要做什么:namespaceW{namespacehide{templatestd::ostream&operatorstructC{Tt_;std::stringToString()const{usingnamespacehide;std::ostringstreamoss;oss这很好用,但有一些注意事项。例如,如果我想为一个类实际提供一个重载的插入运算符,那么该