Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
String 如何正确使用无序地图?_String_Unordered Map - Fatal编程技术网

String 如何正确使用无序地图?

String 如何正确使用无序地图?,string,unordered-map,String,Unordered Map,我正在写一个程序,它应该计算一个3个字符长的字符串出现的次数。我有一个循环,它从一个较大的字符串中生成3个字符的子字符串,但是当我试图将它们插入一个无序的_映射时,我会得到一系列错误。我做错了什么 int a =0; std::string subs= ""; std::unordered_map <std::string,int> mapp = {}; int count=0; for(int i=0; i<ss.length(); i++){ subs= ss.su

我正在写一个程序,它应该计算一个3个字符长的字符串出现的次数。我有一个循环,它从一个较大的字符串中生成3个字符的子字符串,但是当我试图将它们插入一个无序的_映射时,我会得到一系列错误。我做错了什么

int a =0;

std::string subs= "";

std::unordered_map <std::string,int> mapp = {};
int count=0;

for(int i=0; i<ss.length(); i++){

subs= ss.substr(a,k);
if(subs.length()<k){
   return -1;
}
    std::cout << "Substring: " << subs << std::endl;
    a++;
    mapp.insert(std::make_pair<std::string,int>(subs,count));

  }
inta=0;
std::string subs=“”;
std::无序的_映射mapp={};
整数计数=0;

对于(int i=0;iPerhaps而不是猜测其成员函数的参数将有所帮助。这与您对该方法所做的操作不匹配。@WhozCraig Oops!我在发布之前没有更改更新的插入行。假设我理解正确,我的方法是它只插入第一个子字符串。因此我想指定我的question,我想知道如何遍历其余的子字符串。也许不去猜测它的成员函数的参数会有所帮助。这与你对该方法所做的不匹配。@WhozCraig Oops!我在发布之前没有更改更新过的插入行。假设我理解正确,我使用它的方式是不正确的hat它只插入第一个子字符串。所以我想指定我的问题,我想找出如何迭代其余的子字符串。