我在使用 cxxparse/cxxparse4101 解析简单的 C++ 源文件时遇到错误。有人可以帮我吗?
c++ 文件:
//map.cpp
#include<iostream>
#include<map>
#include<string>
using std::string;
using std::to_string;
class A{
public:
int a;
std::string tostring(){return to_string(a);}
};
当我使用命令
cxxparse map.cpp
时,出现错误:
"map.cpp", line 6: error: namespace "std" has no member "to_string"
using std::to_string;
^
"map.cpp", line 11: error: identifier "to_string" is undefined
std::string tostring(){return to_string(a);}
^
2 errors detected in the compilation of "map.cpp".
PDT: Error: Couldn't create map.pdb: Invoking the alternate PDT parser based on EDG v4.10.1:
/home/caicadmin/xiongyongfeng/pdtoolkit-3.25.1/x86_64//bin/cxxparse4101 map.cpp
PDT: Trying edgcpfe4101 without CXXSTDOPT=--c++11
/home/caicadmin/xiongyongfeng/pdtoolkit-3.25.1/x86_64//bin/edgcpfe4101 --sys_include /home/caicadmin/xiongyongfeng/pdtoolkit-3.25.1/contrib/rose/rose-header-gen/include/g++_HEADERS --sys_include /home/caicadmin/xiongyongfeng/pdtoolkit-3.25.1/contrib/rose/rose-header-gen/include/g++_HEADERS --sys_include /home/caicadmin/xiongyongfeng/pdtoolkit-3.25.1/contrib/rose/rose-header-gen/include/g++_HEADERS/hdrs --sys_include /home/caicadmin/xiongyongfeng/pdtoolkit-3.25.1/contrib/rose/rose-header-gen/include/g++_HEADERS/hdrs1 --sys_include /home/caicadmin/xiongyongfeng/pdtoolkit-3.25.1/contrib/rose/rose-header-gen/include/g++_HEADERS/hdrs2 --sys_include /opt/rh/devtoolset-7/root/usr/lib/gcc/x86_64-redhat-linux/7/../../../../include/c++/7 --sys_include /opt/rh/devtoolset-7/root/usr/lib/gcc/x86_64-redhat-linux/7/../../../../include/c++/7/x86_64-redhat-linux --sys_include /opt/rh/devtoolset-7/root/usr/lib/gcc/x86_64-redhat-linux/7/../../../../include/c++/7/backward --sys_include /opt/rh/devtoolset-7/root/usr/lib/gcc/x86_64-redhat-linux/7/include --sys_include /usr/local/include --sys_include /usr/include -DPDT_PARSER -DPDT_PARSER_EDG4101 -D__GNUG__=7 -D__GNUC__=7 -D__GNUC_MINOR__=7 -D__GNUC_PATCHLEVEL__=7 --preinclude rose_edg_required_macros_and_functions.h -DROSE_LANGUAGE_MODE=1 -tused --g++ --gnu_version 77700 --edg_base_dir /home/caicadmin/xiongyongfeng/pdtoolkit-3.25.1/contrib/rose/rose-header-gen -o /tmp/pdt.caicadmin.568.il map.cpp
"map.cpp", line 6: error: namespace "std" has no member "to_string"
using std::to_string;
^
"map.cpp", line 11: error: identifier "to_string" is undefined
std::string tostring(){return to_string(a);}
^
2 errors detected in the compilation of "map.cpp".
平台信息:
pdt 配置命令:
./configure && make && make install
希望能收到回复。
当我评论
#include<map>
或不使用 std::to_string 时,cxxparse/cxxparse4101 可以工作。我不知道是什么原因。也许在配置 pdt 源代码时应该添加“-std=c++11”。我尝试使用CXXFLAGS="-std=c++11" ./configure && make && make install
,但不起作用。我仔细阅读了pdt源代码的README文件,没有说明如何设置std=c++11选项标志。
有人可以给我一些建议吗?
谢谢你
试试这个代码:
#include<iostream>
#include<map>
#include<string>
class A{
public:
int a;
std::string tostring(){return std::to_string(a);}
};
int main(){
A abc;
abc.a = 3;
std::cout <<abc.tostring() << std::endl;
}