【发布时间】:2016-10-08 11:01:49
【问题描述】:
我有一些旧版 C++ 代码(用于使用 GNU g++ 2.95.3 编译)具有以下声明 std::basic_string<char,string_char_traits<char>,malloc_alloc> x;
头文件是
#include <std/bastring.h>
现在,我正在迁移到 GU g++ 4.9,但出现此错误:
1.std/bastring.h未找到
2. 当我将#include <std/bastring.h> 更改为#include <string> 时,出现以下错误:
error: 'string_char_traits' was not declared in this scope
std::basic_string<char,string_char_traits<char>,malloc_alloc> x;
error: template argument 2 is invalid
std::basic_string<char,string_char_traits<char>,malloc_alloc> x;
error: expected unqualified-id before ',' token
std::basic_string<char,string_char_traits<char>,malloc_alloc> x;
^
需要指导/帮助以使其可在 GNU g++ 4.9 下编译
【问题讨论】:
-
你知道为什么首先使用
malloc_alloc而不仅仅是alloc吗?您可能只需使用std::string就可以逃脱惩罚。 -
@DieterLücking 致命错误:std/bastring:没有这样的文件或目录
-
@TartanLlama 我不知道为什么用 malloc_alloc 代替 alloc,你是说 std::string 会和 std::basic_string 一样吗?
-
std::string只是std::basic_string<char, std::char_traits<char>, std::allocator<char>>的 typedef,所以只要默认分配器满足您的需求,就可以。
标签: c++ string c++11 g++ g++4.9