Program Database Toolkit(PDT) cxxparse/cxxparse4101 解析包含“#include<map>”和“std::to_string”的简单 C++ 文件时出错

问题描述 投票:0回答:1

我在使用 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".

平台信息:

  • CentOS Linux 版本 7.9.2009(核心)
  • g++(海湾合作委员会)7.3.1 20180303

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选项标志。

有人可以给我一些建议吗?

谢谢你

c++ c++11 stdstring
1个回答
0
投票

试试这个代码:

 #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;
 }
© www.soinside.com 2019 - 2024. All rights reserved.