# ‘string\_view’ is not a member of ‘std’ error. c++ version error?

**URL:** <https://root-forum.cern.ch/t/string-view-is-not-a-member-of-std-error-c-version-error/47713>\
**Category:** Newbie\
**Created:** [November 17, 2021, 9:57pm UTC](https://root-forum.cern.ch/t/string-view-is-not-a-member-of-std-error-c-version-error/47713 "2021-11-17T21:57:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jwbae](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/j/9fc29f/32.png) [@jwbae](https://root-forum.cern.ch/u/jwbae)\
**Post date:** [November 17, 2021, 9:57pm UTC](https://root-forum.cern.ch/t/string-view-is-not-a-member-of-std-error-c-version-error/47713/1 "2021-11-17T21:57:14Z")

</div>

\_ROOT Version:6.24  
\_Platform: WSL (Ubuntu 20.04)  
\_Compiler: gcc 9.3.0, cmake 3.16.3

Dear all,

Hi. I’m trying to compile geant4 example written with ROOT. But I encountered following errors. It looks like an error of c++ version, but when I force the c++ version into c++17, using ‘CMAKE\_CXX\_FLAGS=-std=c++17’ then the compiling is totally crashed with 5k error lines. Should I install the downgraded version of root?

```auto
Scanning dependencies of target sim
[8%] Building CXX object CMakeFiles/sim.dir/sim.cc.o
[16%] Building CXX object CMakeFiles/sim.dir/src/ActionInitialization.cc.o
In file included from /home/jwbae/root/include/TString.h:29,
                 from /home/jwbae/root/include/TNamed.h:26,
                 from /home/jwbae/root/include/TDirectory.h:24,
                 from /home/jwbae/root/include/TDirectoryFile.h:25,
                 from /home/jwbae/root/include/TFile.h:28,
                 from /home/jwbae/workspace/sim_minimal/sim_minimal/include/RunAction.hh:39,
                 from /home/jwbae/workspace/sim_minimal/sim_minimal/src/ActionInitialization.cc:33:
/home/jwbae/root/include/ROOT/RStringView.hxx:32:37: error: ‘experimental’ in namespace ‘std’ does not name a type
   32 | using basic_string_view = ::std::experimental::basic_string_view<_CharT,_Traits>;
      | ^ ~~~~~~~~~~~
/home/jwbae/root/include/ROOT/RStringView.hxx:35:12: error: ‘basic_string_view’ does not name a type
   35 | typedef basic_string_view<char> string_view;
      | ^ ~~~~~~~~~~~~~~~~
/home/jwbae/root/include/ROOT/RStringView.hxx:36:12: error: ‘basic_string_view’ does not name a type
   36 | typedef basic_string_view<char16_t> u16string_view;
      | ^ ~~~~~~~~~~~~~~~~
/home/jwbae/root/include/ROOT/RStringView.hxx:37:12: error: ‘basic_string_view’ does not name a type
   37 | typedef basic_string_view<char32_t> u32string_view;
      | ^ ~~~~~~~~~~~~~~~~
/home/jwbae/root/include/ROOT/RStringView.hxx:38:12: error: ‘basic_string_view’ does not name a type
   38 | typedef basic_string_view<wchar_t> wstring_view;
      | ^ ~~~~~~~~~~~~~~~~
/home/jwbae/root/include/ROOT/RStringView.hxx:48:4: warning: inline variables are only available with ‘-std=c++17’ or ‘-std=gnu++17’
   48 | inline double stod(std::string_view str, size_t *pos)
      | ^ ~~~~~
/home/jwbae/root/include/ROOT/RStringView.hxx:48:28: error: ‘string_view’ is not a member of ‘std’
   48 | inline double stod(std::string_view str, size_t *pos)
      | ^ ~~~~~~~~~~
/home/jwbae/root/include/ROOT/RStringView.hxx:48:28: note: ‘std::string_view’ is only available from C++17 onwards
/home/jwbae/root/include/ROOT/RStringView.hxx:48:52: error: expected primary-expression before ‘*’ token
   48 | inline double stod(std::string_view str, size_t *pos)
      | ^
/home/jwbae/root/include/ROOT/RStringView.hxx:48:53: error: ‘pos’ was not declared in this scope; did you mean ‘pow’?
   48 | inline double stod(std::string_view str, size_t *pos)
      | ^~~
      | pow
/home/jwbae/root/include/ROOT/RStringView.hxx:48:56: error: expression list treated as compound expression in initializer [-fpermissive]
   48 | inline double stod(std::string_view str, size_t *pos)
      | ^
/home/jwbae/root/include/ROOT/RStringView.hxx:65:56: error: ‘std::string_view’ has not been declared
   65 | inline std::string &operator+=(std::string &left, std::string_view right)
      | ^ ~~~~~~~~~~
/home/jwbae/root/include/ROOT/RStringView.hxx: In function ‘std::string& std::__ROOT::operator+=(std::string&, int)’:
/home/jwbae/root/include/ROOT/RStringView.hxx:67:29: error: request for member ‘data’ in ‘right’, which is of non-class type ‘int’
   67 | return left.append(right.data(), right.size());
      | ^~~~
/home/jwbae/root/include/ROOT/RStringView.hxx:67:43: error: request for member ‘size’ in ‘right’, which is of non-class type ‘int’
   67 | return left.append(right.data(), right.size());
      | ^~~~
/home/jwbae/root/include/ROOT/RStringView.hxx: At global scope:
/home/jwbae/root/include/ROOT/RStringView.hxx:84:17: error: expected type-specifier
   84 | operator std::string_view() const { return std::string_view(fData,fLength); }
      | ^~~
In file included from /home/jwbae/root/include/TNamed.h:26,
                 from /home/jwbae/root/include/TDirectory.h:24,
                 from /home/jwbae/root/include/TDirectoryFile.h:25,
                 from /home/jwbae/root/include/TFile.h:28,
                 from /home/jwbae/workspace/sim_minimal/sim_minimal/include/RunAction.hh:39,
                 from /home/jwbae/workspace/sim_minimal/sim_minimal/src/ActionInitialization.cc:33:
/home/jwbae/root/include/TString.h:115:13: error: expected type-specifier
  115 | operator std::string_view() const { return std::string_view(Data(),fExtent); }
      | ^~~
/home/jwbae/root/include/TString.h:280:32: error: ‘string_view’ in namespace ‘std’ does not name a type
  280 | explicit TString(const std::string_view &sub);
      | ^ ~~~~~~~~~~
/home/jwbae/root/include/TString.h:280:27: note: ‘std::string_view’ is only available from C++17 onwards
  280 | explicit TString(const std::string_view &sub);
      | ^~~
/home/jwbae/root/include/TString.h:317:37: error: ‘string_view’ in namespace ‘std’ does not name a type
  317 | TString &operator=(const std::string_view &s);
      | ^ ~~~~~~~~~~
/home/jwbae/root/include/TString.h:317:32: note: ‘std::string_view’ is only available from C++17 onwards
  317 | TString &operator=(const std::string_view &s);
      | ^~~
/home/jwbae/root/include/TString.h:444:9: error: ‘string_view’ in namespace ‘std’ does not name a type
  444 | std::string_view View() const { return std::string_view(GetPointer(),Length()); }
      | ^ ~~~~~~~~~~
/home/jwbae/root/include/TString.h:444:4: note: ‘std::string_view’ is only available from C++17 onwards
  444 | std::string_view View() const { return std::string_view(GetPointer(),Length()); }
      | ^~~
In file included from /home/jwbae/root/include/TNamed.h:26,
                 from /home/jwbae/root/include/TDirectory.h:24,
                 from /home/jwbae/root/include/TDirectoryFile.h:25,
                 from /home/jwbae/root/include/TFile.h:28,
                 from /home/jwbae/workspace/sim_minimal/sim_minimal/include/RunAction.hh:39,
                 from /home/jwbae/workspace/sim_minimal/sim_minimal/src/ActionInitialization.cc:33:
/home/jwbae/root/include/TString.h:839:53: error: ‘string_view’ in namespace ‘std’ does not name a type
  839 | inline Bool_t operator==(const char *s1, const std::string_view &s2)
      | ^ ~~~~~~~~~~
/home/jwbae/root/include/TString.h:839:48: note: ‘std::string_view’ is only available from C++17 onwards
  839 | inline Bool_t operator==(const char *s1, const std::string_view &s2)
      | ^~~
/home/jwbae/root/include/TString.h:839:15: error: ‘Bool_t operator==(const char*, const int&)’ must have an argument of class or enumerated type
  839 | inline Bool_t operator==(const char *s1, const std::string_view &s2)
      | ^ ~~~~~~~
/home/jwbae/root/include/TString.h:844:37: error: ‘string_view’ in namespace ‘std’ does not name a type
  844 | inline Bool_t operator==(const std::string_view &s1, const char *s2)
      | ^ ~~~~~~~~~~
/home/jwbae/root/include/TString.h:844:32: note: ‘std::string_view’ is only available from C++17 onwards
  844 | inline Bool_t operator==(const std::string_view &s1, const char *s2)
      | ^~~
/home/jwbae/root/include/TString.h:844:15: error: ‘Bool_t operator==(const int&, const char*)’ must have an argument of class or enumerated type
  844 | inline Bool_t operator==(const std::string_view &s1, const char *s2)
      | ^ ~~~~~~~
/home/jwbae/root/include/TString.h:857:37: error: ‘string_view’ in namespace ‘std’ does not name a type
  857 | std::string printValue(const std::string_view* val);
      | ^ ~~~~~~~~~~
/home/jwbae/root/include/TString.h:857:32: note: ‘std::string_view’ is only available from C++17 onwards
  857 | std::string printValue(const std::string_view* val);
      | ^~~
In file included from /home/jwbae/workspace/sim_minimal/sim_minimal/include/RunAction.hh:39,
                 from /home/jwbae/workspace/sim_minimal/sim_minimal/src/ActionInitialization.cc:33:
/home/jwbae/root/include/TFile.h:327:45: error: ‘std::string_view’ has not been declared
  327 | static Bool_t SetCacheFileDir(std::string_view cacheDir, Bool_t operateDisconnected = kTRUE,
      | ^ ~~~~~~~~~~
/home/jwbae/root/include/TFile.h: In static member function ‘static Bool_t TFile::SetCacheFileDir(ROOT::Internal::TStringView, Bool_t, Bool_t)’:
/home/jwbae/root/include/TFile.h:326:36: error: ‘string_view’ is not a member of ‘std’
  326 | { return SetCacheFileDir(std::string_view(cacheDir), operateDisconnected, forceCacheread); }
      | ^ ~~~~~~~~~~
/home/jwbae/root/include/TFile.h:326:36: note: ‘std::string_view’ is only available from C++17 onwards
make[2]: *** [CMakeFiles/sim.dir/build.make:76: CMakeFiles/sim.dir/src/ActionInitialization.cc.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:76: CMakeFiles/sim.dir/all] Error 2
make: *** [Makefile:130: all] Error 2

```

* * *

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [November 18, 2021, 7:59am UTC](https://root-forum.cern.ch/t/string-view-is-not-a-member-of-std-error-c-version-error/47713/2 "2021-11-18T07:59:22Z")

</div>

> [@Installation of a software dependent on root](https://root-forum.cern.ch/t/installation-of-a-software-dependent-on-root/46111/2):
>
> I guess there is a mismatch in the C++ language standard used by different libraries (i.e. GammaCombo and ROOT). You need to make sure that the same “-std=...” C++ compiler flag is used when building all your software. One of the first flags in the output of “root-config --cflags” is " -std=..." (and this tells you what C++ language standard your ROOT binaries were built with). Looking at your first screenshot, I can see “HAS\_CPP17 - Success”. This may suggest that the GammaCombo is using “-s…

> [@TString.h Comilation errors due to C++ version despite ROOT having been compiled with correct version](https://root-forum.cern.ch/t/tstring-h-comilation-errors-due-to-c-version-despite-root-having-been-compiled-with-correct-version/46995/4):
>
> It could be that your “some code” needs some special flag. It could also be that it does not support “c++17” at all (e.g., it supports at most “c++14” or “c++11”). For example, newer Geant 4 supports (note also “=14”): cmake -DGEANT4\_BUILD\_CXXSTD=14 Older Geant 4 supports (note also “=c++11”): cmake -DGEANT4\_BUILD\_CXXSTD=c++11

---

<div class="post-metadata">

**Author:** ![eguiraud](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/eguiraud/32/32217_2.png) [@eguiraud](https://root-forum.cern.ch/u/eguiraud)\
**Post date:** [November 18, 2021, 8:03am UTC](https://root-forum.cern.ch/t/string-view-is-not-a-member-of-std-error-c-version-error/47713/3 "2021-11-18T08:03:40Z")

</div>

You can try to force ROOT and Geant to the same C++ standard version with `-DCMAKE_CXX_STANDARD=17` or similar.

Alternatively you can check which standard ROOT was built with (it will appear in the flags printed by `root-config --cflags`) and force Geant to build with the same standard. Make sure to always start from an empty build directory.

Cheers,  
Enrico
