小编pot*_*eno的帖子

AppleScript 有替换功能吗?

在 VBA 中,用不同的子字符串替换子字符串非常容易,例如objMsg.Body = Replace(objMsg.Body, "<Month\", Format(dtDate1, "mmmm"))"<Month>"电子邮件正文中的当前月份替换。我以前见过与此类似的问题,但它们已经有几年的历史了,而且往往有疯狂的解决方法,几乎​​不值得我花时间。

applescript

7
推荐指数
1
解决办法
5440
查看次数

如何找到向量中的最大元素(C++)?

这是我的代码。我省略了向量的代码,因为它并不重要。

#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)

解决这个问题的最佳方法是什么?

c++ algorithm iterator vector max

5
推荐指数
1
解决办法
3万
查看次数

标签 统计

algorithm ×1

applescript ×1

c++ ×1

iterator ×1

max ×1

vector ×1