相关疑难解决方法(0)

关于正则表达式的gcc 4.8或更早的bug吗?

我试图在C++ 11代码中使用std :: regex,但看起来支持有点儿错误.一个例子:

#include <regex>
#include <iostream>

int main (int argc, const char * argv[]) {
    std::regex r("st|mt|tr");
    std::cerr << "st|mt|tr" << " matches st? " << std::regex_match("st", r) << std::endl;
    std::cerr << "st|mt|tr" << " matches mt? " << std::regex_match("mt", r) << std::endl;
    std::cerr << "st|mt|tr" << " matches tr? " << std::regex_match("tr", r) << std::endl;
}
Run Code Online (Sandbox Code Playgroud)

输出:

st|mt|tr matches st? 1
st|mt|tr matches mt? 1
st|mt|tr matches tr? 0
Run Code Online (Sandbox Code Playgroud)

当使用gcc(MacPorts gcc47 4.7.1_2)4.7.1编译时,使用

g++ *.cc -o test -std=c++11 …
Run Code Online (Sandbox Code Playgroud)

c++ regex gcc libstdc++ c++11

98
推荐指数
2
解决办法
3万
查看次数

在C中是否有类似于Python的expandvars?

我有一个字符串存储在一个被读入字符串的文件中.我希望将*nix shell格式中定义的变量替换为相应的环境值.

例如,环境变量$DEPLOY=/home/user"deploypath=$DEPLOY/dir1"变为"deploypath=/home/user/dir1"

有一个简单的库可以做到这一点吗?

#include "supersimplelib.h"
char *newstr = expandvars(oldstr);
Run Code Online (Sandbox Code Playgroud)

(或类似的)

我明白我可以使用正则表达式lib然后调用,getenv()但我想知道是否还有另一种更简单的方法?

它只能在Linux下编译.

c linux environment-variables

10
推荐指数
1
解决办法
429
查看次数

标签 统计

c ×1

c++ ×1

c++11 ×1

environment-variables ×1

gcc ×1

libstdc++ ×1

linux ×1

regex ×1