Guest User

gcc 10.1.0 can't std::stoull a string

a guest
May 17th, 2020
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | None | 0 0
  1. problem with gcc 10.1.0 installed via guix:
  2. std::stoull cannot work on a regular string, but requires wstring
  3.  
  4. code:
  5.  
  6. #include <iostream>
  7. #include <string>
  8.  
  9. uint64_t _parse_number(std::string::const_iterator& c, const std::string::const_iterator& end)
  10. {
  11. std::string::const_iterator s = c;
  12. while (c != end and isdigit(*c)) ++c;
  13. if (c > s) {
  14. return std::stoull(std::string(s,c));
  15. } else {
  16. return 0;
  17. }
  18. }
  19.  
  20. int main(int argc, char** argv) {
  21. std::string s(argv[1]);
  22. std::string::const_iterator b = s.begin();
  23. std::string::const_iterator e = s.end();
  24. std::cout << _parse_number(b, e) << std::endl;
  25. return 0;
  26. }
  27.  
  28. compile with:
  29.  
  30. g++ test-stoull.cpp -o test-stoull
  31.  
  32. yields this error:
  33.  
  34. test-stoull.cpp: In function ‘uint64_t _parse_number(std::__cxx11::basic_string<char>::const_iterator&, const const_iterator&)’:
  35. test-stoull.cpp:9:33: error: invalid initialization of reference of type ‘const wstring&’ {aka ‘const std::__cxx11::basic_string<wchar_t>&’} from expression of type ‘std::string’ {aka ‘std::__cxx11::basic_string<char>’}
  36. 9 | return std::stoull(std::string(s,c));
  37. | ^~~~~~~~~~~
  38. In file included from /home/erikg/.guix-profile/include/c++/string:55,
  39. from /home/erikg/.guix-profile/include/c++/bits/locale_classes.h:40,
  40. from /home/erikg/.guix-profile/include/c++/bits/ios_base.h:41,
  41. from /home/erikg/.guix-profile/include/c++/ios:42,
  42. from /home/erikg/.guix-profile/include/c++/ostream:38,
  43. from /home/erikg/.guix-profile/include/c++/iostream:39,
  44. from test-stoull.cpp:1:
  45. /home/erikg/.guix-profile/include/c++/bits/basic_string.h:6697:25: note: in passing argument 1 of ‘long long unsigned int std::__cxx11::stoull(const wstring&, std::size_t*, int)’
  46. 6697 | stoull(const wstring& __str, size_t* __idx = 0, int __base = 10)
  47. | ~~~~~~~~~~~~~~~^~~~~
  48.  
  49.  
  50. -> % gcc --version
  51. gcc (GCC) 10.1.0
  52. Copyright (C) 2020 Free Software Foundation, Inc.
  53. This is free software; see the source for copying conditions. There is NO
  54. warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Add Comment
Please, Sign In to add comment