场景:定义了一个结构体,包含一个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. C# 查看动态库的方法

    使用Vs自带工具:开始菜单-->Microsoft Visual Studio 2010--> Visual Studio Tools-->Visual Studio 命令提示符 输 ...

  2. NEXYS 3开发板练手--USB UART(一)

    接上一篇文章,今天来讲讲这个USB UART串口发送机. 我们知道,当我们的微处理器(单片机.FPGA.DSP等)要和电脑进行通信的时候一般会采用串行通信方式,而最常用的串行通信协议的物理层接口是RS ...

  3. AFNetworking、ASIHTTPRequest中SSL的使用

    首先介绍下AFNetworking中的使用: 2.0要注意个地方:IOS7及其以后,採用AFHTTPSessionManager,IOS7之前採用AFHTTPRequestOperationManag ...

  4. zabbix 源

    http://repo.zabbix.com/ # cat /etc/yum.repos.d/zabbix.repo [zabbix] name=Zabbix Official Repository ...

  5. Socket相关函数(1)- socket(), bind(), listen(), accept(), connect(), TCP模型

    tcp_server.c #include <sys/types.h> #include <sys/socket.h> #include <stdio.h> #in ...

  6. windows performance

    blogs.technet.com/b/perfguide/archive/2010/09/28/the-microsoft-pfe-performance-guide-start-here.aspx

  7. ~function(){}() 和(function(){}){}

    使用~function(){}()也是声明并调用函数的方法之一: 这是一段使用~function(){}()来声明函数并调用函数的例子: ~function() { alert(typeof next ...

  8. python @property使用详解

    1.@property,@xx.setter的作用把方法变成属性@property获取属性@xx.setter设置属性 2.使用示例 #@property使用 class Lang(object): ...

  9. hdoj1241 Oil Deposits

    Oil Deposits Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tota ...

  10. ny27 水池数目

    水池数目 时间限制:3000 ms  |  内存限制:65535 KB 难度:4 描述 南阳理工学院校园里有一些小河和一些湖泊,现在,我们把它们通一看成水池,假设有一张我们学校的某处的地图,这个地图上 ...