123456789;
string str = to_string(num);
int l = str.length();
for(int i = 0; i < l; i++){
cout << stoi(str[i]) << " " <<endl;
}
return 0;
} - почему я получаю ошибку: test.cpp: In function ‘int main()’:
test.cpp:13:24: error: no matching function for call to ‘stoi(__gnu_cxx::__alloc_traits<std::allocator<char>, char>::value_type&)’
13 | cout << stoi(str[i]) << " " <<endl;
| ^
In file included from /usr/include/c++/10/string:55,
from /usr/include/c++/10/bits/locale_classes.h:40,
from /usr/include/c++/10/bits/ios_base.h:41,
from /usr/include/c++/10/ios:42,
from /usr/include/c++/10/ostream:38,
from /usr/include/c++/10/iostream:39,
from test.cpp:1:
/usr/include/c++/10/bits/basic_string.h:6546:3: note: candidate: ‘int std::__cxx11::stoi(const string&, std::size_t*, int)’
6546 | stoi(const string& __str, size_t* __idx = 0, int __base = 10)
| ^~~~
/usr/include/c++/10/bits/basic_string.h:6546:22: note: no known conversion for argument 1 from ‘__gnu_cxx::__alloc_traits<std::allocator<char>, char>::value_type’ {aka ‘char’} to ‘const string&’ {aka ‘const std::__cxx11::basic_string<char>&’}
6546 | stoi(const string& __str, size_t* __idx = 0, int __base = 10)
| ~~~~~~~~~~~~^
/usr/include/c++/10/bits/basic_string.h:6677:3: note: candidate: ‘int std::__cxx11::stoi(const wstring&, std::size_t*, int)’
6677 | stoi(const wstring& __str, size_t* __idx = 0, int __base = 10)
| ^~
/usr/include/c++/10/bits/basic_string.h:6677:23: note: no known conversion for argument 1 from ‘__gnu_cxx::__alloc_traits<std::allocator<char>, char>::value_type’ {aka ‘char’} to ‘const wstring&’ {aka ‘const std::__cxx11::basic_string<wchar_t>&’}
6677 | stoi(const wstring& __str, size_t* __idx = 0, int __base = 10)
| ~~~~~~~~~~~~~~~^~~~~ ?
Смотрим что принимает https://en.cppreference.com/w/cpp/string/basic_string/stol
Обсуждают сегодня