iT邦幫忙

0

想請教一下以下的C++ program 錯在那

小弟本是打算弄一個為一段訊息進行加密的CPP program 來玩玩, 順帶喚起很久以前學的c++ 的技巧。 可是, 卻不知為何出了這樣的錯

> (  from /usr/include/libio.h:31,```

>                  from /usr/include/stdio.h:74,
>                  from /usr/include/c++/6/cstdio:42,
>                  from /usr/include/c++/6/ext/string_conversions.h:43,
>                  from /usr/include/c++/6/bits/basic_string.h:5429,
>                  from /usr/include/c++/6/string:52,
>                  from /usr/include/c++/6/bits/locale_classes.h:40,
>                  from /usr/include/c++/6/bits/ios_base.h:41,
>                  from /usr/include/c++/6/ios:42,
>                  from /usr/include/c++/6/ostream:38,
>                  from /usr/include/c++/6/iostream:39,
>                  from main.cpp:9:
> main.cpp: In function ‘void dictionary(std::string*)’:
> main.cpp:19:14: error: ambiguous overload for ‘operator=’ (operand types are ‘std::string {aka std::basic_string}’ and ‘long int’)
>      if (*p = NULL)
>               ^
> In file included from /usr/include/c++/6/string:52:0,
>                  from /usr/include/c++/6/bits/locale_classes.h:40,
>                  from /usr/include/c++/6/bits/ios_base.h:41,
>                  from /usr/include/c++/6/ios:42,
>                  from /usr/include/c++/6/ostream:38,
>                  from /usr/include/c++/6/iostream:39,
>                  from main.cpp:9:
> /usr/include/c++/6/bits/basic_string.h:3096:7: note: candidate: std::basic_string<_CharT, _Traits, _Alloc>& std::basic_string<_CharT, _Traits, _Alloc>::operator=(const std::basic_string<_CharT, _Traits, _Alloc>&) [with _CharT = char; _Traits = std::char_traits; _Alloc = std::allocator]
>        operator=(const basic_string& __str)
>        ^~~~~~~~
> /usr/include/c++/6/bits/basic_string.h:3104:7: note: candidate: std::basic_string<_CharT, _Traits, _Alloc>& std::basic_string<_CharT, _Traits, _Alloc>::operator=(const _CharT*) [with _CharT = char; _Traits = std::char_traits; _Alloc = std::allocator]
>        operator=(const _CharT* __s)
>        ^~~~~~~~
> /usr/include/c++/6/bits/basic_string.h:3115:7: note: candidate: std::basic_string<_CharT, _Traits, _Alloc>& std::basic_string<_CharT, _Traits, _Alloc>::operator=(_CharT) [with _CharT = char; _Traits = std::char_traits; _Alloc = std::allocator]
>        operator=(_CharT __c)
>        ^~~~~~~~
> /usr/include/c++/6/bits/basic_string.h:3131:7: note: candidate: std::basic_string<_CharT, _Traits, _Alloc>& std::basic_string<_CharT, _Traits, _Alloc>::operator=(std::basic_string<_CharT, _Traits, _Alloc>&&) [with _CharT = char; _Traits = std::char_traits; _Alloc = std::allocator]
>        operator=(basic_string&& __str)
>        ^~~~~~~~
> main.cpp:24:12: error: could not convert ‘* p’ from ‘std::string {aka std::basic_string}’ to ‘bool’
>      while (*p)
>             ^~
> main.cpp:26:15: error: no match for ‘operator==’ (operand types are ‘std::string {aka std::basic_string}’ and ‘char’)
>          if(*p == ' ')
>             ~~~^~~~~~
> In file included from /usr/include/c++/6/iosfwd:40:0,
>                  from /usr/include/c++/6/ios:38,
>                  from /usr/include/c++/6/ostream:38,
>                  from /usr/include/c++/6/iostream:39,
>                  from main.cpp:9:
> /usr/include/c++/6/bits/postypes.h:216:5: note: candidate: template bool std::operator==(const std::fpos<_StateT>&, const std::fpos<_StateT>&)
>      operator==(const fpos<_StateT>& __lhs, const fpos<_StateT>& __rhs)
>      ^~~~~~~~
> /usr/include/c++/6/bits/postypes.h:216:5: note:   template argument deduction/substitution failed:
> main.cpp:26:18: note:   ‘std::string {aka std::basic_string}’ is not derived from ‘const std::fpos<_StateT>’
>          if(*p == ' ')
>                   ^~~
> In file included from /usr/include/c++/6/bits/stl_algobase.h:64:0,
>                  from /usr/include/c++/6/bits/char_traits.h:39,
>                  from /usr/include/c++/6/ios:40,
>                  from /usr/include/c++/6/ostream:38,
>                  from /usr/include/c++/6/iostream:39,
>                  from main.cpp:9:
> /usr/include/c++/6/bits/stl_pair.h:440:5: note: candidate: template constexpr bool std::operator==(const std::pair<_T1, _T2>&, const std::pair<_T1, _T2>&)
>      operator==(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
>      ^~~~~~~~
> /usr/include/c++/6/bits/stl_pair.h:440:5: note:   template argument deduction/substitution failed:
> main.cpp:26:18: note:   ‘std::string {aka std::basic_string}’ is not derived from ‘const std::pair<_T1, _T2>’
>          if(*p == ' ')
>                   ^~~
> In file included from /usr/include/c++/6/bits/stl_algobase.h:67:0,
>                  from /usr/include/c++/6/bits/char_traits.h:39,
>                  from /usr/include/c++/6/ios:40,
>                  from /usr/include/c++/6/ostream:38,
>                  from /usr/include/c++/6/iostream:39,
>                  from main.cpp:9:
> /usr/include/c++/6/bits/stl_iterator.h:295:5: note: candidate: template bool std::operator==(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_Iterator>&)
>      operator==(const reverse_iterator<_Iterator>& __x,
>      ^~~~~~~~
> /usr/include/c++/6/bits/stl_iterator.h:295:5: note:   template argument deduction/substitution failed:
> main.cpp:26:18: note:   ‘std::string {aka std::basic_string}’ is not derived from ‘const std::reverse_iterator<_Iterator>’
>          if(*p == ' ')
>                   ^~~
> In file included from /usr/include/c++/6/bits/stl_algobase.h:67:0,
>                  from /usr/include/c++/6/bits/char_traits.h:39,
>                  from /usr/include/c++/6/ios:40,
>                  from /usr/include/c++/6/ostream:38,
>                  from /usr/include/c++/6/iostream:39,
>                  from main.cpp:9:
> /usr/include/c++/6/bits/stl_iterator.h:352:5: note: candidate: template bool std::operator==(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_IteratorR>&)
>      operator==(const reverse_iterator<_IteratorL>& __x,
>      ^~~~~~~~
> /usr/include/c++/6/bits/stl_iterator.h:352:5: note:   template argument deduction/substitution failed:
> main.cpp:26:18: note:   ‘std::string {aka std::basic_string}’ is not derived from ‘const std::reverse_iterator<_Iterator>’
>          if(*p == ' ')
>                   ^~~
> In file included from /usr/include/c++/6/bits/stl_algobase.h:67:0,
>                  from /usr/include/c++/6/bits/char_traits.h:39,
>                  from /usr/include/c++/6/ios:40,
>                  from /usr/include/c++/6/ostream:38,
>                  from /usr/include/c++/6/iostream:39,
>                  from main.cpp:9:
> /usr/include/c++/6/bits/stl_iterator.h:1116:5: note: candidate: template bool std::operator==(const std::move_iterator<_IteratorL>&, const std::move_iterator<_IteratorR>&)
>      operator==(const move_iterator<_IteratorL>& __x,
>      ^~~~~~~~
> /usr/include/c++/6/bits/stl_iterator.h:1116:5: note:   template argument deduction/substitution failed:
> main.cpp:26:18: note:   ‘std::string {aka std::basic_string}’ is not derived from ‘const std::move_iterator<_IteratorL>’
>          if(*p == ' ')
>                   ^~~
> In file included from /usr/include/c++/6/bits/stl_algobase.h:67:0,
>                  from /usr/include/c++/6/bits/char_traits.h:39,
>                  from /usr/include/c++/6/ios:40,
>                  from /usr/include/c++/6/ostream:38,
>                  from /usr/include/c++/6/iostream:39,
>                  from main.cpp:9:
> /usr/include/c++/6/bits/stl_iterator.h:1122:5: note: candidate: template bool std::operator==(const std::move_iterator<_IteratorL>&, const std::move_iterator<_IteratorL>&)
>      operator==(const move_iterator<_Iterator>& __x,
>      ^~~~~~~~
> /usr/include/c++/6/bits/stl_iterator.h:1122:5: note:   template argument deduction/substitution failed:
> main.cpp:26:18: note:   ‘std::string {aka std::basic_string}’ is not derived from ‘const std::move_iterator<_IteratorL>’
>          if(*p == ' ')
>                   ^~~
> In file included from /usr/include/c++/6/string:41:0,
>                  from /usr/include/c++/6/bits/locale_classes.h:40,
>                  from /usr/include/c++/6/bits/ios_base.h:41,
>                  from /usr/include/c++/6/ios:42,
>                  from /usr/include/c++/6/ostream:38,
>                  from /usr/include/c++/6/iostream:39,
>                  from main.cpp:9:
> /usr/include/c++/6/bits/allocator.h:146:5: note: candidate: template bool std::operator==(const std::allocator<_CharT>&, const std::allocator<_T2>&)
>      operator==(const allocator<_T1>&, const allocator<_T2>&)
>      ^~~~~~~~
> /usr/include/c++/6/bits/allocator.h:146:5: note:   template argument deduction/substitution failed:
> main.cpp:26:18: note:   ‘std::string {aka std::basic_string}’ is not derived from ‘const std::allocator<_CharT>’
>          if(*p == ' ')
>                   ^~~
> In file included from /usr/include/c++/6/string:41:0,
>                  from /usr/include/c++/6/bits/locale_classes.h:40,
>                  from /usr/include/c++/6/bits/ios_base.h:41,
>                  from /usr/include/c++/6/ios:42,
>                  from /usr/include/c++/6/ostream:38,
>                  from /usr/include/c++/6/iostream:39,
>                  from main.cpp:9:
> /usr/include/c++/6/bits/allocator.h:152:5: note: candidate: template bool std::operator==(const std::allocator<_CharT>&, const std::allocator<_CharT>&)
>      operator==(const allocator<_Tp>&, const allocator<_Tp>&)
>      ^~~~~~~~
> /usr/include/c++/6/bits/allocator.h:152:5: note:   template argument deduction/substitution failed:
> main.cpp:26:18: note:   ‘std::string {aka std::basic_string}’ is not derived from ‘const std::allocator<_CharT>’
>          if(*p == ' ')
>                   ^~~
> In file included from /usr/include/c++/6/string:52:0,
>                  from /usr/include/c++/6/bits/locale_classes.h:40,
>                  from /usr/include/c++/6/bits/ios_base.h:41,
>                  from /usr/include/c++/6/ios:42,
>                  from /usr/include/c++/6/ostream:38,
>                  from /usr/include/c++/6/iostream:39,
>                  from main.cpp:9:
> /usr/include/c++/6/bits/basic_string.h:5077:5: note: candidate: template bool std::operator==(const std::basic_string<_CharT, _Traits, _Alloc>&, const std::basic_string<_CharT, _Traits, _Alloc>&)
>      operator==(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
>      ^~~~~~~~
> /usr/include/c++/6/bits/basic_string.h:5077:5: note:   template argument deduction/substitution failed:
> main.cpp:26:18: note:   mismatched types ‘const std::basic_string<_CharT, _Traits, _Alloc>’ and ‘char’
>          if(*p == ' ')
>                   ^~~
> In file included from /usr/include/c++/6/string:52:0,
>                  from /usr/include/c++/6/bits/locale_classes.h:40,
>                  from /usr/include/c++/6/bits/ios_base.h:41,
>                  from /usr/include/c++/6/ios:42,
>                  from /usr/include/c++/6/ostream:38,
>                  from /usr/include/c++/6/iostream:39,
>                  from main.cpp:9:
> /usr/include/c++/6/bits/basic_string.h:5085:5: note: candidate: template typename __gnu_cxx::__enable_if::__value, bool>::__type std::operator==(const std::basic_string<_CharT>&, const std::basic_string<_CharT>&)
>      operator==(const basic_string<_CharT>& __lhs,
>      ^~~~~~~~
> /usr/include/c++/6/bits/basic_string.h:5085:5: note:   template argument deduction/substitution failed:
> main.cpp:26:18: note:   mismatched types ‘const std::basic_string<_CharT>’ and ‘char’
>          if(*p == ' ')
>                   ^~~
> In file included from /usr/include/c++/6/string:52:0,
>                  from /usr/include/c++/6/bits/locale_classes.h:40,
>                  from /usr/include/c++/6/bits/ios_base.h:41,
>                  from /usr/include/c++/6/ios:42,
>                  from /usr/include/c++/6/ostream:38,
>                  from /usr/include/c++/6/iostream:39,
>                  from main.cpp:9:
> /usr/include/c++/6/bits/basic_string.h:5099:5: note: candidate: template bool std::operator==(const _CharT*, const std::basic_string<_CharT, _Traits, _Alloc>&)
>      operator==(const _CharT* __lhs,
>      ^~~~~~~~
> /usr/include/c++/6/bits/basic_string.h:5099:5: note:   template argument deduction/substitution failed:
> main.cpp:26:18: note:   mismatched types ‘const _CharT*’ and ‘std::basic_string’
>          if(*p == ' ')
>                   ^~~
> In file included from /usr/include/c++/6/string:52:0,
>                  from /usr/include/c++/6/bits/locale_classes.h:40,
>                  from /usr/include/c++/6/bits/ios_base.h:41,
>                  from /usr/include/c++/6/ios:42,
>                  from /usr/include/c++/6/ostream:38,
>                  from /usr/include/c++/6/iostream:39,
>                  from main.cpp:9:
> /usr/include/c++/6/bits/basic_string.h:5111:5: note: candidate: template bool std::operator==(const std::basic_string<_CharT, _Traits, _Alloc>&, const _CharT*)
>      operator==(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
>      ^~~~~~~~
> /usr/include/c++/6/bits/basic_string.h:5111:5: note:   template argument deduction/substitution failed:
> main.cpp:26:18: note:   mismatched types ‘const _CharT*’ and ‘char’
>          if(*p == ' ')
>                   ^~~
> In file included from /usr/include/c++/6/bits/ios_base.h:46:0,
>                  from /usr/include/c++/6/ios:42,
>                  from /usr/include/c++/6/ostream:38,
>                  from /usr/include/c++/6/iostream:39,
>                  from main.cpp:9:
> /usr/include/c++/6/system_error:284:3: note: candidate: bool std::operator==(const std::error_code&, const std::error_code&)
>    operator==(const error_code& __lhs, const error_code& __rhs) noexcept
>    ^~~~~~~~
> /usr/include/c++/6/system_error:284:3: note:   no known conversion for argument 1 from ‘std::string {aka std::basic_string}’ to ‘const std::error_code&’
> /usr/include/c++/6/system_error:289:3: note: candidate: bool std::operator==(const std::error_code&, const std::error_condition&)
>    operator==(const error_code& __lhs, const error_condition& __rhs) noexcept
>    ^~~~~~~~
> /usr/include/c++/6/system_error:289:3: note:   no known conversion for argument 1 from ‘std::string {aka std::basic_string}’ to ‘const std::error_code&’
> /usr/include/c++/6/system_error:296:3: note: candidate: bool std::operator==(const std::error_condition&, const std::error_code&)
>    operator==(const error_condition& __lhs, const error_code& __rhs) noexcept
>    ^~~~~~~~
> /usr/include/c++/6/system_error:296:3: note:   no known conversion for argument 1 from ‘std::string {aka std::basic_string}’ to ‘const std::error_condition&’
> /usr/include/c++/6/system_error:303:3: note: candidate: bool std::operator==(const std::error_condition&, const std::error_condition&)
>    operator==(const error_condition& __lhs,
>    ^~~~~~~~
> /usr/include/c++/6/system_error:303:3: note:   no known conversion for argument 1 from ‘std::string {aka std::basic_string}’ to ‘const std::error_condition&’
> In file included from /usr/include/c++/6/bits/locale_facets.h:48:0,
>                  from /usr/include/c++/6/bits/basic_ios.h:37,
>                  from /usr/include/c++/6/ios:44,
>                  from /usr/include/c++/6/ostream:38,
>                  from /usr/include/c++/6/iostream:39,
>                  from main.cpp:9:
> /usr/include/c++/6/bits/streambuf_iterator.h:204:5: note: candidate: template bool std::operator==(const std::istreambuf_iterator<_CharT, _Traits>&, const std::istreambuf_iterator<_CharT, _Traits>&)
>      operator==(const istreambuf_iterator<_CharT, _Traits>& __a,
>      ^~~~~~~~
> /usr/include/c++/6/bits/streambuf_iterator.h:204:5: note:   template argument deduction/substitution failed:
> main.cpp:26:18: note:   ‘std::string {aka std::basic_string}’ is not derived from ‘const std::istreambuf_iterator<_CharT, _Traits>’
>          if(*p == ' ')
>                   ^~~
> In file included from /usr/include/x86_64-linux-gnu/c++/6/bits/c++allocator.h:33:0,
>                  from /usr/include/c++/6/bits/allocator.h:46,
>                  from /usr/include/c++/6/string:41,
>                  from /usr/include/c++/6/bits/locale_classes.h:40,
>                  from /usr/include/c++/6/bits/ios_base.h:41,
>                  from /usr/include/c++/6/ios:42,
>                  from /usr/include/c++/6/ostream:38,
>                  from /usr/include/c++/6/iostream:39,
>                  from main.cpp:9:
> /usr/include/c++/6/ext/new_allocator.h:139:5: note: candidate: template bool __gnu_cxx::operator==(const __gnu_cxx::new_allocator<_Tp>&, const __gnu_cxx::new_allocator<_Tp>&)
>      operator==(const new_allocator<_Tp>&, const new_allocator<_Tp>&)
>      ^~~~~~~~
> /usr/include/c++/6/ext/new_allocator.h:139:5: note:   template argument deduction/substitution failed:
> main.cpp:26:18: note:   ‘std::string {aka std::basic_string}’ is not derived from ‘const __gnu_cxx::new_allocator<_Tp>’
>          if(*p == ' ')
>                   ^~~
> In file included from /usr/include/c++/6/bits/stl_algobase.h:67:0,
>                  from /usr/include/c++/6/bits/char_traits.h:39,
>                  from /usr/include/c++/6/ios:40,
>                  from /usr/include/c++/6/ostream:38,
>                  from /usr/include/c++/6/iostream:39,
>                  from main.cpp:9:
> /usr/include/c++/6/bits/stl_iterator.h:866:5: note: candidate: template bool __gnu_cxx::operator==(const __gnu_cxx::__normal_iterator<_Iterator, _Container>&, const __gnu_cxx::__normal_iterator<_Iterator, _Container>&)
>      operator==(const __normal_iterator<_Iterator, _Container>& __lhs,
>      ^~~~~~~~
> /usr/include/c++/6/bits/stl_iterator.h:866:5: note:   template argument deduction/substitution failed:
> main.cpp:26:18: note:   ‘std::string {aka std::basic_string}’ is not derived from ‘const __gnu_cxx::__normal_iterator<_Iterator, _Container>’
>          if(*p == ' ')
>                   ^~~
> In file included from /usr/include/c++/6/bits/stl_algobase.h:67:0,
>                  from /usr/include/c++/6/bits/char_traits.h:39,
>                  from /usr/include/c++/6/ios:40,
>                  from /usr/include/c++/6/ostream:38,
>                  from /usr/include/c++/6/iostream:39,
>                  from main.cpp:9:
> /usr/include/c++/6/bits/stl_iterator.h:859:5: note: candidate: template bool __gnu_cxx::operator==(const __gnu_cxx::__normal_iterator<_IteratorL, _Container>&, const __gnu_cxx::__normal_iterator<_IteratorR, _Container>&)
>      operator==(const __normal_iterator<_IteratorL, _Container>& __lhs,
>      ^~~~~~~~
> /usr/include/c++/6/bits/stl_iterator.h:859:5: note:   template argument deduction/substitution failed:
> main.cpp:26:18: note:   ‘std::string {aka std::basic_string}’ is not derived from ‘const __gnu_cxx::__normal_iterator<_IteratorL, _Container>’
>          if(*p == ' ')
>                   ^~~
> main.cpp:32:20: error: no match for ‘operator==’ (operand types are ‘std::string {aka std::basic_string}’ and ‘char’)
>              if (*p == lett[t])
>                  ~~~^~~~~~~~~~
> In file included from /usr/include/c++/6/iosfwd:40:0,
>                  from /usr/include/c++/6/ios:38,
>                  from /usr/include/c++/6/ostream:38,
>                  from /usr/include/c++/6/iostream:39,
>                  from main.cpp:9:
> /usr/include/c++/6/bits/postypes.h:216:5: note: candidate: template bool std::operator==(const std::fpos<_StateT>&, const std::fpos<_StateT>&)
>      operator==(const fpos<_StateT>& __lhs, const fpos<_StateT>& __rhs)
>      ^~~~~~~~
> /usr/include/c++/6/bits/postypes.h:216:5: note:   template argument deduction/substitution failed:
> main.cpp:32:29: note:   ‘std::string {aka std::basic_string}’ is not derived from ‘const std::fpos<_StateT>’
>              if (*p == lett[t])
>                              ^
> In file included from /usr/include/c++/6/bits/stl_algobase.h:64:0,
>                  from /usr/include/c++/6/bits/char_traits.h:39,
>                  from /usr/include/c++/6/ios:40,
>                  from /usr/include/c++/6/ostream:38,
>                  from /usr/include/c++/6/iostream:39,
>                  from main.cpp:9:
> /usr/include/c++/6/bits/stl_pair.h:440:5: note: candidate: template constexpr bool std::operator==(const std::pair<_T1, _T2>&, const std::pair<_T1, _T2>&)
>      operator==(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
>      ^~~~~~~~
> /usr/include/c++/6/bits/stl_pair.h:440:5: note:   template argument deduction/substitution failed:
> main.cpp:32:29: note:   ‘std::string {aka std::basic_string}’ is not derived from ‘const std::pair<_T1, _T2>’
>              if (*p == lett[t])
>                              ^
> In file included from /usr/include/c++/6/bits/stl_algobase.h:67:0,
>                  from /usr/include/c++/6/bits/char_traits.h:39,
>                  from /usr/include/c++/6/ios:40,
>                  from /usr/include/c++/6/ostream:38,
>                  from /usr/include/c++/6/iostream:39,
>                  from main.cpp:9:
> /usr/include/c++/6/bits/stl_iterator.h:295:5: note: candidate: template bool std::operator==(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_Iterator>&)
>      operator==(const reverse_iterator<_Iterator>& __x,
>      ^~~~~~~~
> /usr/include/c++/6/bits/stl_iterator.h:295:5: note:   template argument deduction/substitution failed:
> main.cpp:32:29: note:   ‘std::string {aka std::basic_string}’ is not derived from ‘const std::reverse_iterator<_Iterator>’
>              if (*p == lett[t])
>                              ^
> In file included from /usr/include/c++/6/bits/stl_algobase.h:67:0,
>                  from /usr/include/c++/6/bits/char_traits.h:39,
>                  from /usr/include/c++/6/ios:40,
>                  from /usr/include/c++/6/ostream:38,
>                  from /usr/include/c++/6/iostream:39,
>                  from main.cpp:9:
> /usr/include/c++/6/bits/stl_iterator.h:352:5: note: candidate: template bool std::operator==(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_IteratorR>&)
>      operator==(const reverse_iterator<_IteratorL>& __x,
>      ^~~~~~~~
> /usr/include/c++/6/bits/stl_iterator.h:352:5: note:   template argument deduction/substitution failed:
> main.cpp:32:29: note:   ‘std::string {aka std::basic_string}’ is not derived from ‘const std::reverse_iterator<_Iterator>’
>              if (*p == lett[t])
>                              ^
> In file included from /usr/include/c++/6/bits/stl_algobase.h:67:0,
>                  from /usr/include/c++/6/bits/char_traits.h:39,
>                  from /usr/include/c++/6/ios:40,
>                  from /usr/include/c++/6/ostream:38,
>                  from /usr/include/c++/6/iostream:39,
>                  from main.cpp:9:
> /usr/include/c++/6/bits/stl_iterator.h:1116:5: note: candidate: template bool std::operator==(const std::move_iterator<_IteratorL>&, const std::move_iterator<_IteratorR>&)
>      operator==(const move_iterator<_IteratorL>& __x,
>      ^~~~~~~~
> /usr/include/c++/6/bits/stl_iterator.h:1116:5: note:   template argument deduction/substitution failed:
> main.cpp:32:29: note:   ‘std::string {aka std::basic_string}’ is not derived from ‘const std::move_iterator<_IteratorL>’
>              if (*p == lett[t])
>                              ^
> In file included from /usr/include/c++/6/bits/stl_algobase.h:67:0,
>                  from /usr/include/c++/6/bits/char_traits.h:39,
>                  from /usr/include/c++/6/ios:40,
>                  from /usr/include/c++/6/ostream:38,
>                  from /usr/include/c++/6/iostream:39,
>                  from main.cpp:9:
> /usr/include/c++/6/bits/stl_iterator.h:1122:5: note: candidate: template bool std::operator==(const std::move_iterator<_IteratorL>&, const std::move_iterator<_IteratorL>&)
>      operator==(const move_iterator<_Iterator>& __x,
>      ^~~~~~~~
> /usr/include/c++/6/bits/stl_iterator.h:1122:5: note:   template argument deduction/substitution failed:
> main.cpp:32:29: note:   ‘std::string {aka std::basic_string}’ is not derived from ‘const std::move_iterator<_IteratorL>’
>              if (*p == lett[t])
>                              ^
> In file included from /usr/include/c++/6/string:41:0,
>                  from /usr/include/c++/6/bits/locale_classes.h:40,
>                  from /usr/include/c++/6/bits/ios_base.h:41,
>                  from /usr/include/c++/6/ios:42,
>                  from /usr/include/c++/6/ostream:38,
>                  from /usr/include/c++/6/iostream:39,
>                  from main.cpp:9:
> /usr/include/c++/6/bits/allocator.h:146:5: note: candidate: template bool std::operator==(const std::allocator<_CharT>&, const std::allocator<_T2>&)
>      operator==(const allocator<_T1>&, const allocator<_T2>&)
>      ^~~~~~~~
> /usr/include/c++/6/bits/allocator.h:146:5: note:   template argument deduction/substitution failed:
> main.cpp:32:29: note:   ‘std::string {aka std::basic_string}’ is not derived from ‘const std::allocator<_CharT>’
>              if (*p == lett[t])
>                              ^
> In file included from /usr/include/c++/6/string:41:0,
>                  from /usr/include/c++/6/bits/locale_classes.h:40,
>                  from /usr/include/c++/6/bits/ios_base.h:41,
>                  from /usr/include/c++/6/ios:42,
>                  from /usr/include/c++/6/ostream:38,
>                  from /usr/include/c++/6/iostream:39,
>                  from main.cpp:9:
> /usr/include/c++/6/bits/allocator.h:152:5: note: candidate: template bool std::operator==(const std::allocator<_CharT>&, const std::allocator<_CharT>&)
>      operator==(const allocator<_Tp>&, const allocator<_Tp>&)
>      ^~~~~~~~
> /usr/include/c++/6/bits/allocator.h:152:5: note:   template argument deduction/substitution failed:
> main.cpp:32:29: note:   ‘std::string {aka std::basic_string}’ is not derived from ‘const std::allocator<_CharT>’
>              if (*p == lett[t])
>                              ^
> In file included from /usr/include/c++/6/string:52:0,
>                  from /usr/include/c++/6/bits/locale_classes.h:40,
>                  from /usr/include/c++/6/bits/ios_base.h:41,
>                  from /usr/include/c++/6/ios:42,
>                  from /usr/include/c++/6/ostream:38,
>                  from /usr/include/c++/6/iostream:39,
>                  from main.cpp:9:
> /usr/include/c++/6/bits/basic_string.h:5077:5: note: candidate: template bool std::operator==(const std::basic_string<_CharT, _Traits, _Alloc>&, const std::basic_string<_CharT, _Traits, _Alloc>&)
>      operator==(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
>      ^~~~~~~~
> /usr/include/c++/6/bits/basic_string.h:5077:5: note:   template argument deduction/substitution failed:
> main.cpp:32:29: note:   mismatched types ‘const std::basic_string<_CharT, _Traits, _Alloc>’ and ‘char’
>              if (*p == lett[t])
>                              ^
> In file included from /usr/include/c++/6/string:52:0,
>                  from /usr/include/c++/6/bits/locale_classes.h:40,
>                  from /usr/include/c++/6/bits/ios_base.h:41,
>                  from /usr/include/c++/6/ios:42,
>                  from /usr/include/c++/6/ostream:38,
>                  from /usr/include/c++/6/iostream:39,
>                  from main.cpp:9:
> /usr/include/c++/6/bits/basic_string.h:5085:5: note: candidate: template typename __gnu_cxx::__enable_if::__value, bool>::__type std::operator==(const std::basic_string<_CharT>&, const std::basic_string<_CharT>&)
>      operator==(const basic_string<_CharT>& __lhs,
>      ^~~~~~~~
> /usr/include/c++/6/bits/basic_string.h:5085:5: note:   template argument deduction/substitution failed:
> main.cpp:32:29: note:   mismatched types ‘const std::basic_string<_CharT>’ and ‘char’
>              if (*p == lett[t])
>                              ^
> In file included from /usr/include/c++/6/string:52:0,
>                  from /usr/include/c++/6/bits/locale_classes.h:40,
>                  from /usr/include/c++/6/bits/ios_base.h:41,
>                  from /usr/include/c++/6/ios:42,
>                  from /usr/include/c++/6/ostream:38,
>                  from /usr/include/c++/6/iostream:39,
>                  from main.cpp:9:
> /usr/include/c++/6/bits/basic_string.h:5099:5: note: candidate: template bool std::operator==(const _CharT*, const std::basic_string<_CharT, _Traits, _Alloc>&)
>      operator==(const _CharT* __lhs,
>      ^~~~~~~~
> /usr/include/c++/6/bits/basic_string.h:5099:5: note:   template argument deduction/substitution failed:
> main.cpp:32:29: note:   mismatched types ‘const _CharT*’ and ‘std::basic_string’
>              if (*p == lett[t])
>                              ^
> In file included from /usr/include/c++/6/string:52:0,
>                  from /usr/include/c++/6/bits/locale_classes.h:40,
>                  from /usr/include/c++/6/bits/ios_base.h:41,
>                  from /usr/include/c++/6/ios:42,
>                  from /usr/include/c++/6/ostream:38,
>                  from /usr/include/c++/6/iostream:39,
>                  from main.cpp:9:
> /usr/include/c++/6/bits/basic_string.h:5111:5: note: candidate: template bool std::operator==(const std::basic_string<_CharT, _Traits, _Alloc>&, const _CharT*)
>      operator==(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
>      ^~~~~~~~
> /usr/include/c++/6/bits/basic_string.h:5111:5: note:   template argument deduction/substitution failed:
> main.cpp:32:29: note:   mismatched types ‘const _CharT*’ and ‘char’
>              if (*p == lett[t])
>                              ^
> In file included from /usr/include/c++/6/bits/ios_base.h:46:0,
>                  from /usr/include/c++/6/ios:42,
>                  from /usr/include/c++/6/ostream:38,
>                  from /usr/include/c++/6/iostream:39,
>                  from main.cpp:9:
> /usr/include/c++/6/system_error:284:3: note: candidate: bool std::operator==(const std::error_code&, const std::error_code&)
>    operator==(const error_code& __lhs, const error_code& __rhs) noexcept
>    ^~~~~~~~
> /usr/include/c++/6/system_error:284:3: note:   no known conversion for argument 1 from ‘std::string {aka std::basic_string}’ to ‘const std::error_code&’
> /usr/include/c++/6/system_error:289:3: note: candidate: bool std::operator==(const std::error_code&, const std::error_condition&)
>    operator==(const error_code& __lhs, const error_condition& __rhs) noexcept
>    ^~~~~~~~
> /usr/include/c++/6/system_error:289:3: note:   no known conversion for argument 1 from ‘std::string {aka std::basic_string}’ to ‘const std::error_code&’
> /usr/include/c++/6/system_error:296:3: note: candidate: bool std::operator==(const std::error_condition&, const std::error_code&)
>    operator==(const error_condition& __lhs, const error_code& __rhs) noexcept
>    ^~~~~~~~
> /usr/include/c++/6/system_error:296:3: note:   no known conversion for argument 1 from ‘std::string {aka std::basic_string}’ to ‘const std::error_condition&’
> /usr/include/c++/6/system_error:303:3: note: candidate: bool std::operator==(const std::error_condition&, const std::error_condition&)
>    operator==(const error_condition& __lhs,
>    ^~~~~~~~
> /usr/include/c++/6/system_error:303:3: note:   no known conversion for argument 1 from ‘std::string {aka std::basic_string}’ to ‘const std::error_condition&’
> In file included from /usr/include/c++/6/bits/locale_facets.h:48:0,
>                  from /usr/include/c++/6/bits/basic_ios.h:37,
>                  from /usr/include/c++/6/ios:44,
>                  from /usr/include/c++/6/ostream:38,
>                  from /usr/include/c++/6/iostream:39,
>                  from main.cpp:9:
> /usr/include/c++/6/bits/streambuf_iterator.h:204:5: note: candidate: template bool std::operator==(const std::istreambuf_iterator<_CharT, _Traits>&, const std::istreambuf_iterator<_CharT, _Traits>&)
>      operator==(const istreambuf_iterator<_CharT, _Traits>& __a,
>      ^~~~~~~~
> /usr/include/c++/6/bits/streambuf_iterator.h:204:5: note:   template argument deduction/substitution failed:
> main.cpp:32:29: note:   ‘std::string {aka std::basic_string}’ is not derived from ‘const std::istreambuf_iterator<_CharT, _Traits>’
>              if (*p == lett[t])
>                              ^
> In file included from /usr/include/x86_64-linux-gnu/c++/6/bits/c++allocator.h:33:0,
>                  from /usr/include/c++/6/bits/allocator.h:46,
>                  from /usr/include/c++/6/string:41,
>                  from /usr/include/c++/6/bits/locale_classes.h:40,
>                  from /usr/include/c++/6/bits/ios_base.h:41,
>                  from /usr/include/c++/6/ios:42,
>                  from /usr/include/c++/6/ostream:38,
>                  from /usr/include/c++/6/iostream:39,
>                  from main.cpp:9:
> /usr/include/c++/6/ext/new_allocator.h:139:5: note: candidate: template bool __gnu_cxx::operator==(const __gnu_cxx::new_allocator<_Tp>&, const __gnu_cxx::new_allocator<_Tp>&)
>      operator==(const new_allocator<_Tp>&, const new_allocator<_Tp>&)
>      ^~~~~~~~
> /usr/include/c++/6/ext/new_allocator.h:139:5: note:   template argument deduction/substitution failed:
> main.cpp:32:29: note:   ‘std::string {aka std::basic_string}’ is not derived from ‘const __gnu_cxx::new_allocator<_Tp>’
>              if (*p == lett[t])
>                              ^
> In file included from /usr/include/c++/6/bits/stl_algobase.h:67:0,
>                  from /usr/include/c++/6/bits/char_traits.h:39,
>                  from /usr/include/c++/6/ios:40,
>                  from /usr/include/c++/6/ostream:38,
>                  from /usr/include/c++/6/iostream:39,
>                  from main.cpp:9:
> /usr/include/c++/6/bits/stl_iterator.h:866:5: note: candidate: template bool __gnu_cxx::operator==(const __gnu_cxx::__normal_iterator<_Iterator, _Container>&, const __gnu_cxx::__normal_iterator<_Iterator, _Container>&)
>      operator==(const __normal_iterator<_Iterator, _Container>& __lhs,
>      ^~~~~~~~
> /usr/include/c++/6/bits/stl_iterator.h:866:5: note:   template argument deduction/substitution failed:
> main.cpp:32:29: note:   ‘std::string {aka std::basic_string}’ is not derived from ‘const __gnu_cxx::__normal_iterator<_Iterator, _Container>’
>              if (*p == lett[t])
>                              ^
> In file included from /usr/include/c++/6/bits/stl_algobase.h:67:0,
>                  from /usr/include/c++/6/bits/char_traits.h:39,
>                  from /usr/include/c++/6/ios:40,
>                  from /usr/include/c++/6/ostream:38,
>                  from /usr/include/c++/6/iostream:39,
>                  from main.cpp:9:
> /usr/include/c++/6/bits/stl_iterator.h:859:5: note: candidate: template bool __gnu_cxx::operator==(const __gnu_cxx::__normal_iterator<_IteratorL, _Container>&, const __gnu_cxx::__normal_iterator<_IteratorR, _Container>&)
>      operator==(const __normal_iterator<_IteratorL, _Container>& __lhs,
>      ^~~~~~~~
> /usr/include/c++/6/bits/stl_iterator.h:859:5: note:   template argument deduction/substitution failed:
> main.cpp:32:29: note:   ‘std::string {aka std::basic_string}’ is not derived from ‘const __gnu_cxx::__normal_iterator<_IteratorL, _Container>’
              if (*p == lett[t])
                              ^
 main.cpp: In function ‘int main()’:
 main.cpp:72:23: error: cannot convert ‘std::string {aka std::basic_string}’ to ‘std::string* {aka std::basic_string*}’ for argument ‘1’ to ‘void dictionary(std::string*)’
      dictionary(wordsin);
                       ^)
                       
                       
以下的則是小弟的program。 望能得到指點一下。 因為是網上的simulator 來弄的,所以未能提供code 的cpp file, 望能見諒。



#include <iostream>

using namespace std;

int let [26];
char lett [] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
 
void dictionary(string *p)
{
    int numwords = 0;
    if (*p = NULL)
    {
        cout <<"nothing here are";
    }
    
    while (*p)
    {
        if(*p == ' ')
        cout<<"2335";
        int t =0;
        int k =0;
        while (k=0)
        {
            if (*p == lett[t])
            {
                if (t<25)
                {
                    cout << lett[t+1];
                }
                else
                {
                    cout <<lett [t-1];
                }
                ++k;
            }
            else if (t<=25)
            {
                ++t;
            }
            else
            {
                cout<<"Error occur";
                break;
            }
            *p++;
            
        }
    }
    

}



int main()
{
    for (int n=0;n<25;n++)
    {
        let[n] = n;
    };
    cout<<"please enter the word for changing password \n";
    string wordsin;
    cin>>wordsin;
    dictionary(wordsin);
    return 0;
}

null

小魚 iT邦大師 1 級 ‧ 2021-06-28 12:46:43 檢舉
請先用```在上跟下把程式碼包起來.
另外這有點多,
除非是剛好有空,
要不然很難無償幫忙看.
最好是自己學會Debug...
froce iT邦大師 1 級 ‧ 2021-06-28 13:00:58 檢舉
if (p = NULL)...

debug告訴你告訴得很清楚了,為何不看呢?
allship iT邦新手 5 級 ‧ 2021-06-28 13:59:30 檢舉
...你不提醒, 我還真的沒有看到...謝謝 (OWO)/
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

2 個回答

0
EN
iT邦好手 1 級 ‧ 2021-06-28 13:13:38
void dictionary(string *p)
{
int numwords = 0;
if (*p = NULL)
{
cout <<"nothing here are";
}
// ...
}

當中的 *p = NULL 會把 Pointer p 指向的記憶體內容改成 NULL ,要做比較請改為 ==

BTW: 建議你去學一下 Markdown ,不然你的問題真的還蠻辣眼睛的...

allship iT邦新手 5 級 ‧ 2021-06-28 13:58:17 檢舉

/images/emoticon/emoticon02.gif

原來如此, 謝謝你的解答

0
JamesDoge
iT邦高手 1 級 ‧ 2023-02-14 09:36:15
#include <iostream>

using namespace std;

int let[26];
char lett[] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};

void dictionary(string* p)
{
    int numwords = 0;
    // 使用 p == nullptr 來判斷 p 是否為空指針
    if (p == nullptr) {
        cout << "nothing here are";
        return;
    }
    // 使用 p->empty() 來判斷是否已經到字串結尾
    while (!p->empty()) {
        // 使用 (*p)[0] 來取得字串的第一個字元
        if((*p)[0] == ' ') {
            cout << "2335";
        }
        int t = 0;
        int k = 0;
        while (k == 0)
        {
            if ((*p)[0] == lett[t])
            {
                if (t < 25)
                {
                    cout << lett[t + 1];
                }
                else
                {
                    cout << lett[t - 1];
                }
                ++k;
            }
            else if (t <= 25)
            {
                ++t;
            }
            else
            {
                cout << "Error occur";
                break;
            }
            // 使用 p->erase(0, 1) 來移除字串的第一個字元
            p->erase(0, 1);
        }
    }
}

int main()
{
    for (int n = 0; n < 25; n++)
    {
        let[n] = n;
    };
    cout << "please enter the word for changing password \n";
    string wordsin;
    cin >> wordsin;
    dictionary(&wordsin);
    return 0;
}

我要發表回答

立即登入回答