这与问题有关:
尽管现在一切正常,但我唯一无法完成的就是在出现错误时降低用户输入:
功能
bool lookupTerm(const std::string& term, const std::vector<std::string>& possible_names) {
transform(term.begin(), term.end(), term.begin(), ::tolower);
for (const std::string &possible_name : possible_names)
{
if (possible_name.compare(term) == 0)
return true;
}
return false;
}
参数
const std::vector<std::string> possible_asterisk = { "star" ,
"asterisk" ,
"tilde"};
string term = "SoMeWorD";
错误
In file included from /usr/include/c++/7.2.0/algorithm:62:0,
from jdoodle.cpp:5:
/usr/include/c++/7.2.0/bits/stl_algo.h: In instantiation of '_OIter std::transform(_IIter, _IIter, _OIter, _UnaryOperation) [with _IIter = __gnu_cxx::__normal_iterator<const char*, std::__cxx11::basic_string<char> >; _OIter = __gnu_cxx::__normal_iterator<const char*, std::__cxx11::basic_string<char> >; _UnaryOperation = int (*)(int) throw ()]':
jdoodle.cpp:40:64: required from here
/usr/include/c++/7.2.0/bits/stl_algo.h:4306:12: error: assignment of read-only location '__result.__gnu_cxx::__normal_iterator<const char*, std::__cxx11::basic_string<char> >::operator*()'
*__result = __unary_op(*__first);
我知道转换应该接收一个字符串。如何暂时将std::vector转换为简单的字符串,以便我可以将该单词转换为小写?