草庐IT

back-end

全部标签

c++ - 为什么 back_insert_iterator/front_insert_iterator/insert_iterator 的 value_type/difference_type/pointer/reference 都是 void?

在我的项目中,我想将流拆分为一些给定类型的值,所以我实现了一个模板函数templateTOutputIterSplitSpace(std::istream&IS,TOutputIterresult){TElemelem;while(IS>>elem){*result=elem;++result;}returnresult;}我认为这很尴尬,因为我必须在调用时明确给出TElem的类型。例如,我必须写:std::vectorv;SplitSpace(std::cin,back_inserter(v));//IwanttoittobeSplitSpace(std::cin,back_inse

c++ - 为什么 back_insert_iterator/front_insert_iterator/insert_iterator 的 value_type/difference_type/pointer/reference 都是 void?

在我的项目中,我想将流拆分为一些给定类型的值,所以我实现了一个模板函数templateTOutputIterSplitSpace(std::istream&IS,TOutputIterresult){TElemelem;while(IS>>elem){*result=elem;++result;}returnresult;}我认为这很尴尬,因为我必须在调用时明确给出TElem的类型。例如,我必须写:std::vectorv;SplitSpace(std::cin,back_inserter(v));//IwanttoittobeSplitSpace(std::cin,back_inse

c++ - 非数组类型的 "one-past-the-end"指针是 C++ 中的有效概念吗?

C++标准[sec5.7]说:Ifboththepointeroperandandtheresultpointtoelementsofthesamearrayobject,oronepastthelastelementofthearrayobject,theevaluationshallnotproduceanoverflow;otherwise,thebehaviorisundefined.那么,我是否正确地假设除了数组之外的其他类型的指针是未定义的?例如:inta=0;vectorv(&a,(&a)+1);上面的代码片段编译和工作得很好(使用g++),但它有效吗?

c++ - 非数组类型的 "one-past-the-end"指针是 C++ 中的有效概念吗?

C++标准[sec5.7]说:Ifboththepointeroperandandtheresultpointtoelementsofthesamearrayobject,oronepastthelastelementofthearrayobject,theevaluationshallnotproduceanoverflow;otherwise,thebehaviorisundefined.那么,我是否正确地假设除了数组之外的其他类型的指针是未定义的?例如:inta=0;vectorv(&a,(&a)+1);上面的代码片段编译和工作得很好(使用g++),但它有效吗?

c++ - 警告 : extra tokens at end of#endif directive

我正在使用VxWorks6.8C++编译器编译一个相当大的项目。我收到以下警告警告:#endif指令末尾的额外标记#ifndef_OM_NO_IOSTREAM#ifdefWIN32#ifndefUSE_IOSTREAM#defineUSE_IOSTREAM#endifUSE_IOSTREAM#endifWIN32我收到了很多这样的警告。WhyiamgettingthesewarningsandfromC++standardpointofview?Whatisthegoodreasonwhycompileriswarningforthis?Whatisthebestwaytofixthi

c++ - 警告 : extra tokens at end of#endif directive

我正在使用VxWorks6.8C++编译器编译一个相当大的项目。我收到以下警告警告:#endif指令末尾的额外标记#ifndef_OM_NO_IOSTREAM#ifdefWIN32#ifndefUSE_IOSTREAM#defineUSE_IOSTREAM#endifUSE_IOSTREAM#endifWIN32我收到了很多这样的警告。WhyiamgettingthesewarningsandfromC++standardpointofview?Whatisthegoodreasonwhycompileriswarningforthis?Whatisthebestwaytofixthi

c++ - std::vector在push_back和insert(end(),x)之间不一致崩溃

将此代码放入MSVisualC++2010中,进行编译(调试或发布),它将在insert()循环而不是push_back循环时崩溃:#include#includeusingstd::vector;usingstd::string;intmain(){vectorvec1;vec1.push_back("hello");for(inti=0;i!=10;++i)vec1.push_back(vec1[0]);vectorvec2;vec2.push_back("hello");for(inti=0;i!=10;++i)vec2.insert(vec2.end(),vec2[0]);re

c++ - std::vector在push_back和insert(end(),x)之间不一致崩溃

将此代码放入MSVisualC++2010中,进行编译(调试或发布),它将在insert()循环而不是push_back循环时崩溃:#include#includeusingstd::vector;usingstd::string;intmain(){vectorvec1;vec1.push_back("hello");for(inti=0;i!=10;++i)vec1.push_back(vec1[0]);vectorvec2;vec2.push_back("hello");for(inti=0;i!=10;++i)vec2.insert(vec2.end(),vec2[0]);re

c++ - 查找链表的 "Nth node from the end"

这似乎返回了正确的答案,但我不确定这是否真的是处理事情的最佳方式。好像我访问前n个节点的次数太多了。有什么建议么?请注意,我必须使用单链表来执行此操作。Node*findNodeFromLast(Node*head,intn){Node*currentNode;Node*behindCurrent;currentNode=head;for(inti=0;inext){currentNode=currentNode->next;}else{returnNULL;}}behindCurrent=head;while(currentNode->next){currentNode=curren

c++ - 查找链表的 "Nth node from the end"

这似乎返回了正确的答案,但我不确定这是否真的是处理事情的最佳方式。好像我访问前n个节点的次数太多了。有什么建议么?请注意,我必须使用单链表来执行此操作。Node*findNodeFromLast(Node*head,intn){Node*currentNode;Node*behindCurrent;currentNode=head;for(inti=0;inext){currentNode=currentNode->next;}else{returnNULL;}}behindCurrent=head;while(currentNode->next){currentNode=curren