相关疑难解决方法(0)

如何在编译时测试libstdc ++的版本,而不是GCC?

我试图在版本4.9.0之前使用GCC分发的版本中测试libstdc++因为std::regex已实现但很大程度上已破坏的版本libstdc++.

注意:

有没有可靠的方法来测试它的版本libstdc++不依赖于使用GCC我的编译器?

c++ gcc clang libstdc++

6
推荐指数
1
解决办法
834
查看次数

使用eclipse在c ++中编译和正则表达式

所以我的教授给了我一个用c ++编写的正则表达式.

所以我试着在eclipse中编写我的代码(我正在使用linux(ubuntu 12.04)).

所以我拿了代码:

   // regex_search example
#include <iostream>
#include <string>
#include <regex>

int main ()
{
  std::string s ("this subject has a submarine as a subsequence");
  std::smatch m;
  std::regex e ("\\b(sub)([^ ]*)");   // matches words beginning by "sub"

  std::cout << "Target sequence: " << s << std::endl;
  std::cout << "Regular expression: /\\b(sub)([^ ]*)/" << std::endl;
  std::cout << "The following matches and submatches were found:" << std::endl;

  while (std::regex_search (s,m,e)) {
    for (auto x:m) std::cout << x << " …
Run Code Online (Sandbox Code Playgroud)

c++ regex eclipse compiler-errors eclipse-cdt

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

是否对C++的实现有任何监督?

C++代码标准由国际标准化组织(ISO)定义.有许多不同的C++实现,如GCC/G ++,libc/libc ++,clang(++ too),Microsoft Visual C++,英特尔C++编译器等.所以任何人都可以自己实现(编译器等,运行时库,...)并称之为C++.

我想知道:

  • 是否有与C++实现相关的学科?
  • 是否有任何组织(如ISO)控制这些实施以确保它们符合标准?

c++ compiler-construction iso

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

为什么这个C++程序在编译时失败了?

我正在读这个.我在代码块13.12 IDE上测试了这个程序,它支持C++11但是在编译时失败并且编译器显示多个错误.看看这个节目.它适用于在线编译罚款看到这

// bad_array_new_length example
#include <iostream>     // std::cout
#include <exception>    // std::exception
#include <new>          // std::bad_array_new_length

int main() {
  try {
    int* p = new int[-1];
  } catch (std::bad_array_new_length& e) {
    std::cerr << "bad_array_new_length caught: " << e.what() << '\n';
  } catch (std::exception& e) {   // older compilers may throw other exceptions:
    std::cerr << "some other standard exception caught: " << e.what() << '\n';
  }
}
Run Code Online (Sandbox Code Playgroud)

编译器错误:

7   12      [Error] expected type-specifier

7   37 …
Run Code Online (Sandbox Code Playgroud)

c++ exception-handling compiler-errors c++11

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

如何获得-std = c ++ 11 w/libstdc ++?

为什么这不起作用:

#include <regex>
int main() {
   return 0;
}
Run Code Online (Sandbox Code Playgroud)

编译为:

clang++ -std=c++11 -stdlib=libstdc++ temp.cpp
temp.cpp:1:10: fatal error: 'regex' file not found
#include <regex>
         ^
1 error generated.


clang++ --version
Apple LLVM version 7.0.0 (clang-700.1.76)
Target: x86_64-apple-darwin14.5.0
Thread model: posix
Run Code Online (Sandbox Code Playgroud)

如果我能够stdlib成为libc++然后再编译.正则表达式c++11,但clang本身似乎没有问题-std=c++11 -stdlib=libstdc++.至少在我的机器上,它看起来像我可以使用的东西/usr/include/regex.h,但这不是标准的,除了我想使用的正则表达式以外的东西(例如std :: to_string).

这已经想出的原因是因为我想链接到第三方库(对此我没有源),这是符合作为std::string,而不是std::__1::basic_string,但我代码使用std::regex和std::to_string.我不确定是否要引入对boost的依赖.

c++ clang libstdc++ c++11 libc++

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

抛出“std::regex_error”实例后调用终止

我只是想匹配“{”。但不知道为什么会出现这个错误:

terminate called after throwing an instance of 'std::regex_error'
  what():  regex_error
Aborted (core dumped)
Run Code Online (Sandbox Code Playgroud)

在 Ubuntu 上使用 g++ 版本 4.6.3 进行编译

g++   -std=c++0x   a.c
Run Code Online (Sandbox Code Playgroud)

程序

#include<iostream>
#include<regex>


using namespace std;

main(int argc,char**argv){

        if (regex_match("{1}" , std::regex ("[{]"))) {
                cout<<"Hello World"<<endl;
        }

}
Run Code Online (Sandbox Code Playgroud)

我还检查了ECMAScript详细信息,这个正则表达式应该匹配。当我使用 like 时它也不匹配:std::regex ("\\{"))

我怎么了?

c++ ubuntu g++

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

在 CentOS 7 上构建时如何链接 devtoolset-7 中的 libstdc++?

我想devtoolset-7在 CentOS 7 上构建 C++11 应用程序。我正在尝试使用该库,但CentOS 7 本身包含的<regex>版本4.8.4不支持它。libstdc++

我已按照以下说明安装并启用 SCL/ devtoolset-7:

$ sudo yum install centos-release-scl
$ sudo yum install devtoolset-7
$ scl enable devtoolset-7 bash
Run Code Online (Sandbox Code Playgroud)

此时,如果我调用g++,它就是正确的版本 (7.2.1),但是当我构建应用程序并在它们上运行时,它们仍然动态链接到系统上的ldd旧版本。/lib64/libstdc++.so.6可靠链接的最简单方法是什么devtoolset-7-libstdc++-devel-7.2.1?我使用 CMake 3 作为构建系统。

g++ libstdc++ c++11 devtoolset centos7

5
推荐指数
0
解决办法
1492
查看次数

C++ 11 正则表达式错误

只是来自的示例代码C++ Primer 5th Edition: 17.3.3. Using the Regular Expression Library

主要文件main.cpp:

#include <iostream>
#include "regexcase.h"
using namespace std;

int main() {
    using_regex();
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

头文件regexcase.h:

#ifndef REGEXCASE_H_
#define REGEXCASE_H_

#include <regex>
#include <string>

void using_regex();
std::string parseCode(std::regex_constants::error_type etype);

#endif /* REGEXCASE_H_ */
Run Code Online (Sandbox Code Playgroud)

源文件regexcase.cpp:

#include "regexcase.h"
#include <iostream>
using namespace std;

void using_regex() {
    // look for words that violate a well-known spelling rule of thumb, "i before e, except after c":
    // …
Run Code Online (Sandbox Code Playgroud)

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

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

C++ TR1正则表达式不可用

我正在尝试将'TR1'正则表达式扩展用于某些C++字符串解析.我已经读过,<regex>标头和命名空间std :: tr1是必需的

我可以使用<regex>标题编译(虽然它强制我使用标志, -std=c++0x或-std=gnu++0x)

但是,当我尝试std::tr1在程序中使用命名空间时,编译失败并显示tr1"不是命名空间名称"的消息.我不能做的事情,

std::tr1::regex rx("mypattern");

我已经读过自gcc 4.3.0以来一直支持TR1正则表达式.我通过gcc 4.4.5使用g ++.

我错过了什么吗?

c++ regex namespaces g++ tr1

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

如何创建不区分大小写的正则表达式来匹配文件扩展名?

我试图匹配所有具有扩展名的文件.nef- 匹配必须不区分大小写.

regex e("(.*)(\\.NEF)",ECMAScript|icase);
...
if (regex_match ( fn1, e )){
    //Do Something
}
Run Code Online (Sandbox Code Playgroud)

这fn1是一个带有文件名的字符串.

但是,这仅对具有.NEF(大写)扩展名的文件"做某事" ..nef扩展名被忽略.

我也尝试过 -

regex e("(.*)(\\.[Nn][Ee][Ff])");
Run Code Online (Sandbox Code Playgroud)

和

regex e("(.*)(\\.[N|n][E|e][F|f])");
Run Code Online (Sandbox Code Playgroud)

两者都导致运行时错误.

terminate called after throwing an instance of 'std::regex_error'
  what():  regex_error
Aborted (core dumped)
Run Code Online (Sandbox Code Playgroud)

我的代码编译使用 -

g++ nefread.cpp -o nefread -lraw_r -lpthread -pthread -std=c++11 -O3
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?这是我的基本代码.我希望把它扩大到匹配更多的文件扩展名.nef,.raw,.cr2等.

c++ regex c++11

2
推荐指数
1
解决办法
5132
查看次数