标签:stl

怎么样在vector中添加任意小于其容量的元素

最近在研究STL,突然对于vector有个特殊的想法,假设本人定义一个vector的容量为1000,然后用户可能是输入100个元素或74的元素,或其他,我们要做的是把用户的输入存入vector中然后输出,具体的本人写过一段测试代码 #include <iostream> #include <vector> using namespac……

为什么vector::insert在正常使用的时候奇怪的抛出了异常

class Foo{ public:     // 构造和析构     Foo(int iRes) : m_res(iRes) {         m_szData = new unsigned char[iRes * iRes];     };     ~Foo() { if(m_szData) delete[] m_szData; };     // ……

c++使用sort中遇到的问题

第一个问题: STL中comp函数究竟是什么意思?传过去的参数是做什么的?查百度看高手的解释终究还是没看明白。恕本人愚笨,希望通俗一些。 第二个问题: 在comp自定义的函数中使用传值与传址有区别吗? 如代码: #include <iostream> #include <math.h> #include <cstring>……

写好了多项式加法,不会写多项式减法、乘法,求补充

#include <iostream> #include <map> using namespace std; class Polynomial { public: int& coefficient(unsigned degree) { return deg2coeff[degree]; } const int&……

stl lower_bound编译出错

#include <iostream> #include <algorithm> #include <map> #include <string> using namespace std; int main(){ map<string, int> m; map<string, int>:……

POJ C++STL算法部分

描述 写一个本人的 CMyistream_iterator 模板,使之能和 istream_iterator 模板达到一样的效果,即: 输入: 79 90 20 hello me 输出: 79 79,90,20 hello,me #include <iostream> #include <string> using namespace……

c++ set重载'

#include<cstdio> #include<set> using namespace std; class A { public: int a,b,c; friend bool operator <(A a,A b) { return a.a<b.a; } }; int main() { A a1,……