草庐IT

before_first_request

全部标签

c++ - 这里的 (void) first2++ 有什么意义?

这个问题在这里已经有了答案:Whydoesstd::transformandsimilarcastthe'for'loopincrementto(void)?(2个答案)关闭5年前。关于thisen.cppreference的页面有可能实现词典顺序比较的示例。这是基本的:templateboollexicographical_compare(InputIt1first1,InputIt1last1,InputIt2first2,InputIt2last2){for(;(first1!=last1)&&(first2!=last2);first1++,(void)first2++){if

C++ 范围-v3 库 : 'take' -ing first 3 perfect numbers works and halts; 'take' -ing first 4 doesn't stop after 4

据我了解,range-v3库的View操作(目前需要C++17,但要成为C++20中STL的正式部分)提供了可链接的类STL算法,这些算法是延迟计算的。作为实验,我创建了以下代码来评估前4个完全数:#include#includeusingnamespacestd;intmain(intargc,char*argv[]){autoperfects=ranges::view::ints(1)|ranges::view::filter([](intx){intpsum=0;for(inty=1;y代码以可能无限范围的数字开始(ranges::view::ints(1)),但是因为View算

c++ - std::shared_ptr::owner_before 和 std::owner_less: "owner-based order"到底是什么意思?

我发现了一些关于此的讨论,但似乎没有任何内容明确说明“基于所有者的订单”到底是什么。它是否有效评估关于拥有的指针内存地址的值? 最佳答案 它定义了一个任意严格的弱排序,在该排序下,两个指针当且仅当它们共享所有权或均为空时才等效。等价以通常的方式定义:boolequivalent(p1,p2){return!p1.owner_before(p2)&&!p2.owner_before(p1);}这并不一定意味着它们指向同一个对象。两个指针可以指向不同的对象但仍然共享所有权:structthing{intn;};shared_ptrt1=

c++ - 错误 C2146 : syntax error : missing ';' before identifier

我无法摆脱这些错误...我检查的每个地方都有分号...代码很简单:该错误将我带到article.h中的定义“字符串名称”...主要.cpp#include#include#include#includeusingnamespacestd;#include"article.h"intmain(){stringsi;chararticle[128];vectorarticles;ifstreamfile;file.open("input.txt",ifstream::in);while(!file.eof()){file.getline(article,128);articles.push

C++: "error: expected class-name before ‘{’ token"继承模板类时

我四处寻找问题的解决方案,发现了很多关于循环引用和namespace的问题(均不适用于我的情况),但与我遇到的问题完全不同。我在maths/matrix.h中定义并实现了一个模板类:templateclassMatrix{public://constructors,destructorsandwhatnot...};我在maths/vector.h中定义并实现了另一个模板类#includetemplateclassVector:publicMatrix{public://constructors,destructorsandwhatnot...};我在vector.h中收到此错误“ex

c++ - 错误 C2143 : syntax error : missing ';' before 'using'

关闭。这个问题是notreproducibleorwascausedbytypos.它目前不接受答案。这个问题是由于错别字或无法再重现的问题引起的。虽然类似的问题可能是on-topic在这里,这个问题的解决方式不太可能帮助future的读者。关闭8年前。Improvethisquestion这是我的标题:#ifndefHEADER_H#defineHEADER_HclassMath{private:staticenumnames{amin=27,ali=46};public:staticvoiddisplayMessage();}#endif//HEADER_H这是标题定义:#incl

c++ - 搜索空字符串时 find vs find_first_of

在STL中,当我执行s.find("")时,它返回0而s.find_first_of("")返回-1(npos)。造成这种差异的原因是什么? 最佳答案 s.find(t)查找子字符串t在s中的第一次出现。如果t为空,则该事件出现在s的开头,并且s.find(t)将返回0。s.find_first_of(t)在t中查找第一次出现的一个字符。如果t为空字符串,则t中没有字符,所以找不到匹配项,find_first_of将返回npos.Liveonideone. 关于c++-搜索空字符串时fi

c++ - "Expected unqualified-id before ' 命名空间 '"错误

我有以下看似无害的代码:#ifndefUI_H#defineUI_H#includenamespaceui{//Displaysthemainmenu,showingloadedvocabularycards////ReturnsuponcompletionofdisplayvoiddisplayMainMenu();//...Morecodeliketheabove,justcommentsfollowedbyfunctions}#endif这给了我这个错误信息:filepath/ui.h:6:error:expectedunqualified-idbefore'namespace'

c++ - 为什么 "begin/end"与 "first/last"存在差异?

关闭。这个问题是opinion-based.它目前不接受答案。想要改进这个问题?更新问题,以便editingthispost可以用事实和引用来回答它.关闭5年前。Improvethisquestion为什么容器提供"begin"/"end"迭代器而算法需要"first"/"last"迭代器?例如:vector提供.begin()和.end()(cppreference.com,cplusplus.com)。sort需要参数first和last(cppreference.com,cplusplus.com)。编辑:发现一个更大的差异。不仅仅是算法使用“first/last”,它也是容器构

C++ - 错误 : expected unqualified-id before ‘using’

我有一个C++程序,当我尝试编译它时出现错误:calor.h|6|error:expectedunqualified-idbefore‘using’|这是calor类的头文件:#ifndef_CALOR_#define_CALOR_#include"gradiente.h"usingnamespacestd;classCalor:publicGradiente{public:Calor();Calor(inta);~Calor();intgetTemp();intgetMinTemp();voidsetTemp(inta);voidsetMinTemp(inta);voidmostra