我想使用equal算法比较两组,但它给了我一个错误.怎么知道两套是否相等?
if(equal (a.begin(), a.end(), v.begin(), v.end())
Run Code Online (Sandbox Code Playgroud) 我按照以下方式编写代码
#include <iostream>
#include <thread>
#include <map>
using namespace std;
void hi (map<string,map<string,int> > &m ) {
m["abc"]["xyz"] =1;
cout<<"in hi";
}
int main() {
map<string, map<string, int> > m;
thread t = thread (hi, m);
t.join();
cout << m.size();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我通过2D地图m参考hi函数,我更新但它没有反映在main函数中.当我打印m.size()时它只打印零.我可以使用线程将2D地图引用传递给函数吗?
我的代码如下:
int main()
{
thread t[10];
for (int i = 0;i < 10; i++)
t[i] = thread(print,i);//thread creation
for (int i = 0;i < 10; i++)
t[i].join();//waiting maiin to threads to cpmleate execution
cout << "in main";
}
void print(int i) {
cout<<"i:"<<endl;
}
Run Code Online (Sandbox Code Playgroud)
这是最有效的方式,还是有更有效的方法来减少运行时间?
我通过以下方式使用擦除从地图中删除元素,但它无法正常工作.为什么?它并没有全部删除.
float nw_cut=80.0;
for(it=nw_tot1.begin();it!=nw_tot1.end();it++)
{
float f=(float) ((float) it->second/lines)*100.0;
if ( f < nw_cut )
{
nw_tot1.erase(it);
}
}
Run Code Online (Sandbox Code Playgroud)