文字列中の文字の出現を合計するprograを作ったが、私は理解できない奇妙なエラーが出る。文字を数えるときに奇妙なコンパイラエラー
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
int sum=0;
string sir;
vector<int> num;
vector<std::string> letters{"a","b","c","d","e","f","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"};
getline(cin,sir);
for(int i = 0; i < letters.size(); i++) {
sum = std::count(sir.begin(),sir.end(), letters[i]);
num.push_back(sum);
sum=0;
}
return 0;
}
エラーAR
、ここで:sir
の
c:\mingw\bin\..\lib\gcc\mingw32\4.6.2\include\c++\bits\stl_algo.h||In function 'typename std::iterator_traits<_InputIterator>::difference_type std::count(_IIter, _IIter, const _Tp&) [with _IIter = __gnu_cxx::__normal_iterator<char*, std::basic_string<char> >, _Tp = std::basic_string<char>, typename std::iterator_traits<_InputIterator>::difference_type = int]':|
E:\c\Watermelon\main.cpp:15|58|instantiated from here|
c:\mingw\bin\..\lib\gcc\mingw32\4.6.2\include\c++\bits\stl_algo.h|4591|error: no match for 'operator==' in '__first.__gnu_cxx::__normal_iterator<_Iterator, _Container>::operator* [with _Iterator = char*, _Container = std::basic_string<char>, __gnu_cxx::__normal_iterator<_Iterator, _Container>::reference = char&]() == __value'|
c:\mingw\bin\..\lib\gcc\mingw32\4.6.2\include\c++\bits\stl_algo.h|4591|note: candidates are:|
c:\mingw\bin\..\lib\gcc\mingw32\4.6.2\include\c++\functional|2233|note: template<class _Res, class ... _Args> bool std::operator==(std::nullptr_t, const std::function<_Res(_ArgTypes ...)>&)|
c:\mingw\bin\..\lib\gcc\mingw32\4.6.2\include\c++\functional|2227|note: template<class _Res, class ... _Args> bool std::operator==(const std::function<_Res(_ArgTypes ...)>&, std::nullptr_t)|
c:\mingw\bin\..\lib\gcc\mingw32\4.6.2\include\c++\tuple|575|note: template<class ... _TElements, class ... _UElements> bool std::operator==(const std::tuple<_TElements ...>&, const std::tuple<_Elements ...>&)|
c:\mingw\bin\..\lib\gcc\mingw32\4.6.2\include\c++\bits\random.h|5322|note: template<class _RealType> bool std::operator==(const std::piecewise_linear_distribution<_RealType>&, const std::piecewise_linear_distribution<_RealType>&)|
c:\mingw\bin\..\lib\gcc\mingw32\4.6.2\include\c++\bits\random.h|5080|note: template<class _RealType> bool std::operator==(const std::piecewise_constant_distribution<_RealType>&, const std::piecewise_constant_distribution<_RealType>&)|
c:\mingw\bin\..\lib\gcc\mingw32\4.6.2\include\c++\bits\random.h|4841|note: template<class _IntType> bool std::operator==(const std::discrete_distribution<_IntType>&, const std::discrete_distribution<_IntType>&)|
c:\mingw\bin\..\lib\gcc\mingw32\4.6.2\include\c++\bits\random.h|4609|note: template<class _RealType> bool std::operator==(const std::extreme_value_distribution<_RealType>&, const std::extreme_value_distribution<_RealType>&)|
c:\mingw\bin\..\lib\gcc\mingw32\4.6.2\include\c++\bits\random.h|4434|note: template<class _RealType> bool std::operator==(const std::weibull_distribution<_RealType>&, const std::weibull_distribution<_RealType>&)|
c:\mingw\bin\..\lib\gcc\mingw32\4.6.2\include\c++\bits\random.h|4259|note: template<class _RealType> bool std::operator==(const std::exponential_distribution<_RealType>&, const std::exponential_distribution<_RealType>&)|
c:\mingw\bin\..\lib\gcc\mingw32\4.6.2\include\c++\bits\random.h|2459|note: template<class _RealType1> bool std::operator==(const std::gamma_distribution<_RealType>&, const std::gamma_distribution<_RealType>&)|
c:\mingw\bin\..\lib\gcc\mingw32\4.6.2\include\c++\bits\random.h|3715|note: template<class _IntType> bool std::operator==(const std::geometric_distribution<_IntType>&, const std::geometric_distribution<_IntType>&)|
c:\mingw\bin\..\lib\gcc\mingw32\4.6.2\include\c++\bits\random.tcc|1684|note: template<class _RealType1> bool std::operator==(const std::normal_distribution<_RealType>&, const std::normal_distribution<_RealType>&)|
c:\mingw\bin\..\lib\gcc\mingw32\4.6.2\include\c++\bits\random.h|3337|note: bool std::operator==(const std::bernoulli_distribution&, const std::bernoulli_distribution&)|
c:\mingw\bin\..\lib\gcc\mingw32\4.6.2\include\c++\bits\random.h|3337|note: no known conversion for argument 1 from 'char' to 'const std::bernoulli_distribution&'|
c:\mingw\bin\..\lib\gcc\mingw32\4.6.2\include\c++\bits\random.h|2798|note: template<class _RealType> bool std::operator==(const std::cauchy_distribution<_RealType>&, const std::cauchy_distribution<_RealType>&)|
c:\mingw\bin\..\lib\gcc\mingw32\4.6.2\include\c++\bits\random.h|1906|note: template<class _IntType> bool std::operator==(const std::uniform_real_distribution<_IntType>&, const std::uniform_real_distribution<_IntType>&)|
c:\mingw\bin\..\lib\gcc\mingw32\4.6.2\include\c++\bits\random.h|1725|note: template<class _IntType> bool std::operator==(const std::uniform_int_distribution<_IntType>&, const std::uniform_int_distribution<_IntType>&)|
c:\mingw\bin\..\lib\gcc\mingw32\4.6.2\include\c++\bits\stl_vector.h|1273|note: template<class _Tp, class _Alloc> bool std::operator==(const std::vector<_Tp, _Alloc>&, const std::vector<_Tp, _Alloc>&)|
c:\mingw\bin\..\lib\gcc\mingw32\4.6.2\include\c++\bits\streambuf_iterator.h|194|note: template<class _CharT, class _Traits> bool std::operator==(const std::istreambuf_iterator<_CharT, _Traits>&, const std::istreambuf_iterator<_CharT, _Traits>&)|
c:\mingw\bin\..\lib\gcc\mingw32\4.6.2\include\c++\bits\basic_string.h|2460|note: template<class _CharT, class _Traits, class _Alloc> bool std::operator==(const std::basic_string<_CharT, _Traits, _Alloc>&, const _CharT*)|
c:\mingw\bin\..\lib\gcc\mingw32\4.6.2\include\c++\bits\basic_string.h|2448|note: template<class _CharT, class _Traits, class _Alloc> bool std::operator==(const _CharT*, const std::basic_string<_CharT, _Traits, _Alloc>&)|
c:\mingw\bin\..\lib\gcc\mingw32\4.6.2\include\c++\bits\basic_string.h|2434|note: template<class _CharT> typename __gnu_cxx::__enable_if<std::__is_char<_Tp>::__value, bool>::__type std::operator==(const std::basic_string<_CharT>&, const std::basic_string<_CharT>&)|
c:\mingw\bin\..\lib\gcc\mingw32\4.6.2\include\c++\bits\basic_string.h|2427|note: template<class _CharT, class _Traits, class _Alloc> bool std::operator==(const std::basic_string<_CharT, _Traits, _Alloc>&, const std::basic_string<_CharT, _Traits, _Alloc>&)|
c:\mingw\bin\..\lib\gcc\mingw32\4.6.2\include\c++\bits\allocator.h|127|note: template<class _Tp> bool std::operator==(const std::allocator<_Tp1>&, const std::allocator<_Tp1>&)|
c:\mingw\bin\..\lib\gcc\mingw32\4.6.2\include\c++\bits\allocator.h|122|note: template<class _T1, class _T2> bool std::operator==(const std::allocator<_T1>&, const std::allocator<_T2>&)|
c:\mingw\bin\..\lib\gcc\mingw32\4.6.2\include\c++\bits\stl_iterator.h|1031|note: template<class _Iterator> bool std::operator==(const std::move_iterator<_Iterator>&, const std::move_iterator<_Iterator>&)|
c:\mingw\bin\..\lib\gcc\mingw32\4.6.2\include\c++\bits\stl_iterator.h|1025|note: template<class _IteratorL, class _IteratorR> bool std::operator==(const std::move_iterator<_IteratorL>&, const std::move_iterator<_IteratorR>&)|
c:\mingw\bin\..\lib\gcc\mingw32\4.6.2\include\c++\bits\stl_iterator.h|335|note: template<class _IteratorL, class _IteratorR> bool std::operator==(const std::reverse_iterator<_IteratorL>&, const std::reverse_iterator<_IteratorR>&)|
c:\mingw\bin\..\lib\gcc\mingw32\4.6.2\include\c++\bits\stl_iterator.h|285|note: template<class _Iterator> bool std::operator==(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_Iterator>&)|
c:\mingw\bin\..\lib\gcc\mingw32\4.6.2\include\c++\bits\stl_pair.h|201|note: template<class _T1, class _T2> constexpr bool std::operator==(const std::pair<_T1, _T2>&, const std::pair<_T1, _T2>&)|
c:\mingw\bin\..\lib\gcc\mingw32\4.6.2\include\c++\bits\postypes.h|218|note: template<class _StateT> bool std::operator==(const std::fpos<_StateT>&, const std::fpos<_StateT>&)|
c:\mingw\bin\..\lib\gcc\mingw32\4.6.2\include\c++\ext\new_allocator.h|123|note: template<class _Tp> bool __gnu_cxx::operator==(const __gnu_cxx::new_allocator<_Tp>&, const __gnu_cxx::new_allocator<_Tp>&)|
c:\mingw\bin\..\lib\gcc\mingw32\4.6.2\include\c++\bits\stl_iterator.h|805|note: template<class _Iterator, class _Container> bool __gnu_cxx::operator==(const __gnu_cxx::__normal_iterator<_Iterator, _Container>&, const __gnu_cxx::__normal_iterator<_Iterator, _Container>&)|
c:\mingw\bin\..\lib\gcc\mingw32\4.6.2\include\c++\bits\stl_iterator.h|799|note: template<class _IteratorL, class _IteratorR, class _Container> bool __gnu_cxx::operator==(const __gnu_cxx::__normal_iterator<_IteratorL, _Container>&, const __gnu_cxx::__normal_iterator<_IteratorR, _Container>&)|
||=== Build finished: 36 errors, 0 warnings ===|
'sir'が' string sir; 'と宣言されたときに' sir'が 'char'である理由を説明したいかもしれません。 –
@CodyGray:' sir'は 'char'です。 – ybungalobill
ありがとう、私はそれを解決しました。ここにコードです:http://ideone.com/RrepR – ddacot