编辑:没关系。现在起作用了。谁知道呢。我的头撞到墙上了。
在2013中运行以下代码时,它将无法工作,而原始字符串将未经修改而打印出来。使用"C++ 2014“在线运行代码时,它是正确的,'*‘是在')’和‘9’之间添加的到底怎么回事?
实时代码可在ideone.com/2mq4u3上使用。
std::string ss ("1 + (3+2)9 - 2 ");
std::regex ee ("(\\)\\d)([^ ])");
std::string result;
std::regex_replace (std::back_inserter(result), ss.begin(), ss.end(), ee, ")*$1");
std::cout << result;实时代码输出:1 + (3+2)*9 - 2
2013年产出:1 + (3+2)9 - 2
发布于 2015-05-01 18:37:22
此代码在Visual中运行:
std::string ss ("1 + (3+2)9 - 2 ");
std::regex ee ("\\)(\\d)");
std::string result;
std::regex_replace (std::back_inserter(result), ss.begin(), ss.end(), ee, ")*$1");
std::cout << result;控制台窗口:

实际上,你可以用:
std::regex ee("\\)(\\d)");
std::string result = std::regex_replace (ss, ee, ")*$1");您将得到相同的输出。
以下是我所拥有的包括:
#include "stdafx.h"
#include <iostream>
#include <string>
#include <regex>
using namespace std;https://stackoverflow.com/questions/29992601
复制相似问题