cout and say 请教大神
//大神给看下 n=8,iter 怎么越界了 class Solution { public: string countAndSay(int n) { string str = "11"; auto iter = str.begin(); if (n == 1) { return "1"; } if (n == 2) { return "11"; } if (n >= 3) { for (int j = 0; j < n - 2; j++) { int count = 1; int length = str.size(); cout << "length:" << length << endl; for (int i = 0; i < length; i++) { if (i <length - 1) { if (str[i] == str[i + 1]) { count++; if (i + 1 == length - 1) { str.push_back(str[i]); count = 1; break; } } else { str.push_back(char(count + 48)); str.push_back(str[i]); count = 1; } } else { str.push_back('1'); str.push_back(str[i]); count = 1; break; } } iter = str.erase(iter, iter + length);//这里 iter = str.begin();//这里 } return str; } } };#C++工程师#