查询 没有匹配的功能用于调用'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被声明为(来自升压参考(

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);

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

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

最新更新