for (auto it1 = m_lockRects.begin(); it1 != m_lockRects.end();it1 ++) { it1->clear(); } m_lockRects.clear(); { for (auto rectList : m_attri->lockRectLists) { std::map<int,int> lockRectMap; int i = 0; for (auto pos : rectList) { lockRectMap.insert(make_pair(i,pos)); i++; } m_lockRects.push_back(lockRectMap); } }
时间: 2024-02-14 11:31:42 浏览: 43
这段代码的作用是清空并重新填充一个名为 m_lockRects 的容器。首先,通过循环遍历 m_lockRects 容器中的元素,并调用 clear() 方法清空每个元素。然后,调用 clear() 方法清空整个 m_lockRects 容器。
接下来,通过循环遍历 m_attri->lockRectLists 容器中的元素 rectList,创建一个名为 lockRectMap 的 map 容器。然后,通过循环遍历 rectList 中的每个元素 pos,将其插入到 lockRectMap 容器中,键为 i,值为 pos。接着,将 lockRectMap 容器插入到 m_lockRects 容器的末尾。
这样,m_lockRects 容器中就包含了 m_attri->lockRectLists 中每个 rectList 的对应的 lockRectMap。整个过程实现了清空和重新填充 m_lockRects 容器的功能。
相关问题
for(auto it=mp_trans.begin()+1;it!=mp_trans.end();it++)这句错在哪里
这句代码中的问题在于,对于大多数 C++ 容器来说,不支持通过 `begin()` 返回的迭代器进行指针算术运算。因此,使用 `begin()` 返回的迭代器不能直接进行加法操作。
要解决这个问题,可以使用 `std::next` 函数来获得从第二个元素开始的迭代器。下面是修改后的代码:
```cpp
for (auto it = std::next(mp_trans.begin()); it != mp_trans.end(); ++it) {
std::cout << it->first << " => " << it->second << '\n';
}
```
在这个示例中,我们使用了 `std::next` 函数来获得从第二个元素开始的迭代器。`std::next` 接受一个迭代器和一个偏移量作为参数,并返回指定偏移量后的迭代器。
通过将 `mp_trans.begin()` 作为参数传递给 `std::next`,我们获得了从第二个元素开始的迭代器,并将其用于循环遍历。
请注意,为了使用 `std::next` 函数,您需要包含 `<iterator>` 头文件。
for(it = m_ctrls.begin(); it!=m_ctrls.end(); ++it) { ::GetClassName(it->m_hCtrl, pszCN, sizeof(pszCN)); if (strcmp(pszCN, a_pszClassName) == 0) { cnt++; it->m_hFix = a_hFix; it->m_vFix = a_vFix; } }怎样把pszCN转化为LPCTSTR型
将pszCN转换为LPCTSTR类型的字符串,可以直接使用字符串类型转换宏定义T()。
例如,以下代码将pszCN转换为LPCTSTR类型的字符串:
```
for(it = m_ctrls.begin(); it!=m_ctrls.end(); ++it) {
::GetClassName(it->m_hCtrl, pszCN, sizeof(pszCN));
if (strcmp(pszCN, T(a_pszClassName)) == 0) {
cnt++;
it->m_hFix = a_hFix;
it->m_vFix = a_vFix;
}
}
```
这里使用了T()宏将a_pszClassName转换为LPCTSTR类型的字符串,然后再与pszCN进行字符串比较。T()宏会根据UNICODE宏的定义,在需要时自动转换为Unicode或者ANSI编码的字符串。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)