简体   繁体   English

cquery没有调用'to_upper'的匹配功能

[英]cquery no matching funtion for call 'to_upper'

#include <iostream>
#include <string>
#include <boost/algorithm/string.hpp>
using namespace std;

int main() {
  string city1, city2;
  cout << ("Please enter your citys name");
  cin >> city1;
  cout << ("Please enter your citys second name");
  cin >> city2;
  cout << city1 [0,1,2,3,4];
  cout << city2 [0,1,2,3,4];
  boost::to_upper(city1, city2);
  cout << city1,city2;
}

This is my code and for some reason boost::to_upper(city1, city2);这是我的代码,出于某种原因 boost::to_upper(city1, city2); gets the error: [cquery] no matching funtion for call 'to_upper'得到错误:[cquery] 没有匹配的函数调用 'to_upper'

boost::algorithm::to_upper is declared as (from boost reference ) boost::algorithm::to_upper声明为(来自boost 参考

template<typename WritableRangeT> 
void to_upper(WritableRangeT & Input, const std::locale & Loc = std::locale());

so you can pass only one string to this function.所以你只能向这个函数传递一个字符串。 Replacing更换

boost::to_upper(city1, city2);

with

boost::to_upper(city1);
boost::to_upper(city2);

makes the code compile and an example output is Please enter your citys namePlease enter your citys second nameosLONDON .使代码编译,示例输出是Please enter your citys namePlease enter your citys second nameosLONDON It lacks newline characters and there is one more mistake - misunderstanding of comma operator.它缺少换行符,还有一个错误 - 对逗号运算符的误解。 Generally comma is used to separate arguments or array elements but in lines通常逗号用于分隔参数或数组元素,但在行中

cout << city1 [0,1,2,3,4];
cout << city2 [0,1,2,3,4];
// ...
cout << city1,city2;

comma operator is used.使用逗号运算符。 Comma operators takes two operands and it's value is value of the right operand (eg after int x = (1, 2); variable x is equal to 2).逗号运算符有两个操作数,它的值是右操作数的值(例如在int x = (1, 2);变量x等于 2)。 Code above is equivalent to上面的代码等价于

cout << city1[4];
cout << city2[4];
// ...
cout << city1;
city2;

Finally, the corrected code is最后,更正后的代码是

#include <iostream>
#include <string>
#include <boost/algorithm/string.hpp>
using namespace std;

int main() {
  string city1, city2;
  cout << "Please enter your citys name" << std::endl;
  cin >> city1;
  cout << "Please enter your citys second name" << std::endl;
  cin >> city2;
  cout << city1 << std::endl;
  cout << city2  << std::endl;
  boost::to_upper(city1);
  boost::to_upper(city2);
  cout << city1 << std::endl << city2 << std::endl;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM