[英]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;
}
这是我的代码,出于某种原因 boost::to_upper(city1, city2); 得到错误:[cquery] 没有匹配的函数调用 'to_upper'
boost::algorithm::to_upper
声明为(来自boost 参考)
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;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.