【问题标题】:cquery no matching funtion for call 'to_upper'cquery没有匹配函数调用'toupper'
【发布时间】:2020-09-26 09:44:57
【问题描述】:
#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;
}

这是我的代码,出于某种原因 boost::to_upper(city1, city2);得到错误:[cquery] no matching function for call 'to_upper'

【问题讨论】:

  • 不是boost::algorithm::to_upper吗? Do not use using namespace stdcquery 只是语言服务器。有什么理由使用boost 而不是 C++ &lt;algorithm&gt;

标签: c++ boost


【解决方案1】:

boost::algorithm::to_upper 被声明为(来自boost reference

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

所以你只能将一个字符串传递给这个函数。更换

boost::to_upper(city1, city2);

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

使代码编译,示例输出为Please enter your citys namePlease enter your citys second nameosLONDON。 它缺少换行符,还有一个错误——对逗号运算符的误解。通常逗号用于分隔参数或数组元素,但在行中

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

使用逗号操作符。逗号运算符有两个操作数,其值为右操作数的值(例如,在int x = (1, 2); 变量x 等于2 之后)。上面的代码相当于

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

最后,修正后的代码是

#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;
}

【讨论】:

    猜你喜欢
    • 2011-10-31
    • 1970-01-01
    • 2017-10-16
    • 1970-01-01
    • 1970-01-01
    • 2021-09-21
    • 2016-11-23
    • 2016-08-08
    相关资源
    最近更新 更多