在调用之后std::regex_search,我只能从std::smatch某些原因得到第一个字符串结果:
Expression.assign("rel=\"nofollow\">(.*?)</a>");
if (std::regex_search(Tables, Match, Expression))
{
for (std::size_t i = 1; i < Match.size(); ++i)
std::cout << Match[i].str() << std::endl;
}
Run Code Online (Sandbox Code Playgroud)
所以我尝试用另一种方式 - 用迭代器:
const std::sregex_token_iterator End;
Expression.assign("rel=\"nofollow\">(.*?)</a>");
for (std::sregex_token_iterator i(Tables.begin(), Tables.end(), Expression); i != End; ++i)
{
std::cout << *i << std::endl;
}
Run Code Online (Sandbox Code Playgroud)
这确实贯穿了每一场比赛,但它也给了我整个匹配的字符串,而不仅仅是我之后的捕获.当然必须是另一种方式,而不是必须std::regex_search在循环中的迭代器元素上做另一个?
提前致谢.
我的A-star实施方面遇到了问题.它确实找到了从我的A点到B点的路径,但是如果地形更"复杂",那么我的Find()函数似乎没有结束.例如,它在这里可以在20 x 20阵列上工作,但是如果你在最右边的障碍物/墙壁的底部添加一个方形('#'),那么它就会失败.
我希望有人可以指出我正在做的任何错误.这是我的代码:
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <utility>
#include <algorithm>
#include <queue>
using namespace std;
class CNode
{
public:
CNode() : xPos(0), yPos(0), travelCost(0) {}
CNode(int x, int y) : xPos(x), yPos(y), travelCost(0) {}
CNode(int x, int y, int cost) : xPos(x), yPos(y), travelCost(cost) {}
inline CNode& operator=(const CNode& target)
{
if (*this != target)
{
xPos = target.xPos;
yPos = target.yPos;
travelCost = target.travelCost;
}
return *this;
}
inline bool operator==(const CNode& target) …Run Code Online (Sandbox Code Playgroud)