在 VBA 中,用不同的子字符串替换子字符串非常容易,例如objMsg.Body = Replace(objMsg.Body, "<Month\", Format(dtDate1, "mmmm"))
用"<Month>"
电子邮件正文中的当前月份替换。我以前见过与此类似的问题,但它们已经有几年的历史了,而且往往有疯狂的解决方法,几乎不值得我花时间。
这是我的代码。我省略了向量的代码,因为它并不重要。
#include <string>
#include <iostream>
#include <vector>
using namespace std;
int main() {
vector<int> scores;
// code to make vector
cout << "High score: " << scores[std::max(scores.begin(), scores.end())] << endl;
system("pause");
}
Run Code Online (Sandbox Code Playgroud)
据我了解, std::max 返回一个迭代器,但我真的不知道如何处理该迭代器。我看过这个例子
*max(scores.begin(), scores.end())
Run Code Online (Sandbox Code Playgroud)
让它返回索引而不是迭代器,但它得到错误
Expression: vector iterator not dereferencable
Run Code Online (Sandbox Code Playgroud)
我尝试使用迭代器,然后使用 std::distance
vector<int>::iterator high = std::max(scores.begin(), scores.end());
cout << "High score: " << scores[std::distance(scores.begin(), high)] << endl;
Run Code Online (Sandbox Code Playgroud)
但我得到了错误
Expression: vector subscript is out of range.
Run Code Online (Sandbox Code Playgroud)
解决这个问题的最佳方法是什么?