C ++ regex: MS VS 2013 output differs from "C ++ 2014 live code" output

EDIT: Nothing. He is working now. Who knows. I bang my head against the wall.

When the following code is executed in MS Visual Studio Express 2013, it does not work and the original line is printed unchanged. When the code is run online using "C ++ 2014" it is correct and "*" is added between ")" and "9." What happens?

Live code is available at 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;

      

Live Code Output: 1 + (3+2)*9 - 2

MS VC 2013 release: 1 + (3+2)9 - 2

+1


source to share


1 answer


This code works in Visual Studio:

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;

      

Console window:

enter image description here

You can actually just use:



std::regex ee("\\)(\\d)");
std::string result = std::regex_replace (ss, ee, ")*$1");

      

You will get the same result.

Here's a list of the inclusions I have:

#include "stdafx.h"
#include <iostream>
#include <string>
#include <regex>
using namespace std;

      

+2


source







All Articles