我知道如何降低一个句子,但我想使用我的字符串修改类来做到这一点。出于某种原因,使用我的 Strmod 对象不起作用,而是通过主要工作来完成。下面是降句代码:
TL;DR,回答:原来我需要通过引用将字符串传递给对象!以下是有效的代码:
transform(statement.begin(), statement.end(), statement.begin(), tolower);
这是我的课程:
class Strmod {
public:
string lower(string &s) {
transform(s.begin(), s.end(), s.begin(), tolower);
return s;
}
};
我这样称呼它:
int main(){
string statement = "";
getline(cin, statement);
Strmod mod;
mod.lower(statement);
cout << statement; //for debugging
}