场景:定义了一个结构体,包含一个vector的成员变量,在给这个vTQ push_back数据的时候报错。

typedef struct tag_TQInfo
{
int iTime;
int iMarket;
string sCode;
vector<string> vTQ; tag_TQInfo()
{
memset(this, 0, sizeof(tag_TQInfo));
}
}TQINFO,*LPTQINFO;

原因:

  tag_TQInfo构造函数用了memset,将分给tag_TQInfo的那块内存都初始化了,也就把vector vTQ自带的东西都清零了,破坏了vector的结构,会导致之后vTQ使用出错。

  vector定义变量时会自己完成初始化工作。

解决方法:

  当结构体中包含vector、string等复杂数据类型,或包含自定义的结构时,构造函数初始化时不能使用memset。 

typedef struct tag_TQInfo
{
int iTime;
int iMarket;
string sCode;
vector<string> vTQ; tag_TQInfo()
: iTime(0)
, iMarket(0)
{ }
}TQINFO,*LPTQINFO;

  

  

vector push_back报错的更多相关文章

  1. std::vector push_back报错Access violation

    C/C++ code   ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 #include < ...

  2. vs.Debug.vector迭代器报错(_ITERATOR_DEBUG_LEVEL)

    1.vs2017.Win7x64 std::vector<ULONG>,在 使用 *iter 取某个 ULONG时 报错,release不报错,报错信息: ZC:具体原理不明,暂时的解决方 ...

  3. c++ 模板参数做容器参数迭代器报错 vector<T>::const_iterator,typename const报错

    错误1: template<class T>void temp(std::vector<T>& container){        std::vector<T& ...

  4. cocos2d-x 头文件中添加方法变量导致编译报错

    代码如下: HelloWorldScene.h #ifndef __HELLOWORLD_SCENE_H__#define __HELLOWORLD_SCENE_H__ #include " ...

  5. caffe ubuntu16安装报错和程序总结

    我最近安装安装了老版本的caffe,安装过程真是两个字"想死",所以我的错误一般都是比较经典的. 我是使用cuda的版本,所以可能会出现undefined refference t ...

  6. 又一种Mysql报错注入

    from:https://rdot.org/forum/showthread.php?t=3167 原文是俄文,所以只能大概的翻译一下 这个报错注入主要基于Mysql的数据类型溢出(不适用于老版本的M ...

  7. boost pool_allocator 报错 'rebind'

    #include "stdafx.h" #include <vector> #include <boost/pool/pool.hpp> int _tmai ...

  8. 报错解决——Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX AVX2

    在导入tensorflow后,进行运算时,出现了报错Your CPU supports instructions that this TensorFlow binary was not compile ...

  9. 加载rocksdb实例报错:java.lang.UnsatisfiedLinkError: C:\Users\Administrator\AppData\Local\Temp\librocksdbjni3696928169151614297.dll

    项目的缓存中用到了rocksdb,实例化时报错了: Related cause: org.springframework.beans.factory.BeanCreationException: Er ...

随机推荐

  1. Intelligence System (hdu 3072 强联通缩点+贪心)

    Intelligence System Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

  2. Python isspace() 方法

    描述 Python isspace() 方法检测字符串是否只由空格组成. 语法 isspace() 方法语法: S.isspace() 参数 无. 返回值 如果字符串中至少有一个字符,并且所有字符都是 ...

  3. python标准库介绍——5 re模块详解

    == re 模块== "Some people, when confronted with a problem, think 'I know, I'll use regular expres ...

  4. python标准库介绍——3 stat 模块详解

    == stat 模块 == [Example 1-50 #eg-1-50] 展示了 ``stat`` 模块的基本用法, 这个模块包含了一些 ``os.stat`` 函数中可用的常量和测试函数. === ...

  5. mac下设置mongodb开机启动方法

    Mac OS 的开机启动方式 launchd 是 Mac OS 下用于初始化系统环境的关键进程,它是内核装载成功之后在OS环境下启动的第一个进程.其实它的作用就是我们平时说的守护进程,简单来说,用户守 ...

  6. oracle ORA-00119和ORA-00132解决方法

    ORA-00119 ORA-00132解决方法. 思路:*.local_listener错误导致.要*.local_listener就要修改spfile文件,因为oracle默认是以spfile文件启 ...

  7. Effective C++ Item 42 了解 typename 的双重意义

    本文为senlie原创,转载请保留此地址:http://blog.csdn.net/zhengsenlie 经验:声明 template 參数时,前缀keyword class 和 typename ...

  8. UNIX环境高级编程(第三版)关于apue.h的用法

    UNIX环境高级编程(第三版)中的例子用到apue.h这个头文件,但是书里面写的地址已经不能访问. 经过一番查找之后,找到如下解决方案: 1.到www.apuebook.com上下载第2版的源码,也可 ...

  9. U3D正播反播动画剪辑

    正播就是直接play item.animation.Play("a"); 反播: item.animation.Play("a"); item.animatio ...

  10. modelsim常见错误

    1. Error: (vlog-7) Failed to open design unit file "D:/Xilinx/verilog/src/glbl.v" in read ...