Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- problem with gcc 10.1.0 installed via guix:
- std::stoull cannot work on a regular string, but requires wstring
- code:
- #include <iostream>
- #include <string>
- uint64_t _parse_number(std::string::const_iterator& c, const std::string::const_iterator& end)
- {
- std::string::const_iterator s = c;
- while (c != end and isdigit(*c)) ++c;
- if (c > s) {
- return std::stoull(std::string(s,c));
- } else {
- return 0;
- }
- }
- int main(int argc, char** argv) {
- std::string s(argv[1]);
- std::string::const_iterator b = s.begin();
- std::string::const_iterator e = s.end();
- std::cout << _parse_number(b, e) << std::endl;
- return 0;
- }
- compile with:
- g++ test-stoull.cpp -o test-stoull
- yields this error:
- test-stoull.cpp: In function ‘uint64_t _parse_number(std::__cxx11::basic_string<char>::const_iterator&, const const_iterator&)’:
- 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>’}
- 9 | return std::stoull(std::string(s,c));
- | ^~~~~~~~~~~
- In file included from /home/erikg/.guix-profile/include/c++/string:55,
- from /home/erikg/.guix-profile/include/c++/bits/locale_classes.h:40,
- from /home/erikg/.guix-profile/include/c++/bits/ios_base.h:41,
- from /home/erikg/.guix-profile/include/c++/ios:42,
- from /home/erikg/.guix-profile/include/c++/ostream:38,
- from /home/erikg/.guix-profile/include/c++/iostream:39,
- from test-stoull.cpp:1:
- /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)’
- 6697 | stoull(const wstring& __str, size_t* __idx = 0, int __base = 10)
- | ~~~~~~~~~~~~~~~^~~~~
- -> % gcc --version
- gcc (GCC) 10.1.0
- Copyright (C) 2020 Free Software Foundation, Inc.
- This is free software; see the source for copying conditions. There is NO
- warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Add Comment
Please, Sign In to add comment