VC6++中Map嵌套Set/Vector等容器


背景

因为公司的编译环境是VC++6.0, 古老的编译器,我用的不太习惯,于是就使用vs2013,在对map嵌套时,2013与VC6.0出现了异常

内容

代码是这样的:
    map<int, set<int>> stlNest;
对于上面这句话,vs2013通过,但是VC6.0报语法错误,错误提示如下:
E:\code\temp\main.cpp(11) : error C2146: syntax error : missing ',' before identifier 'stlNest'
E:\code\temp\main.cpp(11) : error C2065: 'stlNest' : undeclared identifier
E:\code\temp\main.cpp(11) : error C2143: syntax error : missing '>' before ';'
执行 cl.exe 时出错.

main.obj - 1 error(s), 0 warning(s)
因为大家的环境是VC6++,所以为了保证代码合并的时候不出问题,所以我就用了一个比较low的方法,使用结构体把容器包了一下,然后再放到map里面
struct stuSetInt{
    set<int> setInt;
};
map<int, stuSetInt> stlNest;
然后在代码合并的时候己被嘲笑了。。。T.T,然后经过指点,只动了一下,就编过去了
    map<int, set<int> > stlNest;    //你发现区别了么?
就是在`set<int>`后面加了一个空格。。。。泪奔

之前一直没找到为什么这样,今天再看QT学习之路的时候找到了答案
C++ 编译器会将连续的两个 > 当做输入重定向运算符,因此,这里的两个 > 中间必须有一个空格。

好了  问题解决
  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
#!/usr/local/python # -- coding: utf-8 -- import requests import json import logging # Function to get the vCenter server session def get_vc_session(vcip, username, password): s.post('https://' + vcip + '/rest/com/vmware/cis/session', auth=(username, password)) return s # Function to get all the VMs from vCenter inventory def get_vms(vcip,host=''): vms = s.get('https://' + vcip + '/rest/vcenter/vm'+"?filter.hosts="+str(host)) return vms def get_hosts(vcip,cluster=''): result = s.get('https://' + vcip + '/rest/vcenter/host'+"?filter.clusters="+str(cluster)) return result def get_clusters(vcip,dc=''): clusters = s.get('https://' + vcip + '/rest/vcenter/cluster'"?filter.datacenters="+str(dc)) return clusters def get_clusterinfo(vcip,cluster): clusterinfo = s.get('https://' + vcip + '/rest/vcenter/cluster/'+cluster) return clusterinfo def get_datacenters(vcip): datacenters = s.get('https://' + vcip + '/rest/vcenter/datacenter') return datacenters def get_datacenterinfo(vcip,datacenter): datacenterinfo = s.get('https://' + vcip + '/rest/vcenter/datacenter/'+datacenter) return datacenterinfo # Function to power on particular VM def poweron_vm(vmmoid, vcip): s.post('https://' + vcip + '/rest/vcenter/vm/' + vmmoid + '/power/start') # Function to power off particular VM def poweroff_vm(vmmoid, vcip): s.post('https://' + vcip + '/rest/vcenter/vm/' + vmmoid + '/power/stop') def getfolder(vcip): folderinfo = s.get('https://' + vcip + '/rest/vcenter/folder') print(folderinfo) print(dir(folderinfo)) return json.loads(folderinfo.content).values()[0] def gethostlistinfo(vcip): info=get_datacenters(vcip) for dc in json.loads(info.content).values()[0]: dcname=dc.get("name") dcvalue = dc.get("datacenter") #print(dcname,dcvalue) info=get_clusters(vcip, dc=dcvalue) for cls in json.loads(info.content).values()[0]: clustername=cls.get("name") clustervalue = cls.get("cluster") #print(dcname,clustername,clustervalue) info=get_hosts(vcip,cluster=clustervalue) for h in json.loads(info.content).values()[0]: hostip=h.get("name") hostvalue = h.get("host") constate = h.get("connection_state") hostPowerState = h.get("power_state") #print(vcip,dcname,clustername,hostip,constate,power_state) info=get_vms(vcip,hostvalue) for v in json.loads(info.content).values()[0]: vmname = v.get("name") vmvalue = v.get("vm") vmMemSize = v.get("memory_size_MiB") vmCpuCount = v.get("cpu_count") vmPowerState = v.get("power_state") print(vcip,dcname,clustername,hostip,constate,hostPowerState,vmname,vmMemSize,vmCpuCount,vmPowerState) ###main#### vcip='172...' username="administrator@vsphere.local" password="YVd5******" logging.captureWarnings(True) global s s = requests.Session() s.verify = False s = get_vc_session(vcip, username, password) info=gethostlistinfo(vcip) 解释这段代码并改正格式
最新发布
05-30
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值