先看几段代码:
1 string str1 ("aaaaaaaaaa");
2 for(auto it1 = str1.begin(); it1 != str1.end() && !str1.empty(); ++it1 ) {
3 *it1 = toupper(*it1);
4 }
5
6 string str1 ("aaaaaaaaaa");
7 for(auto it = str1.begin(); it != str1.end() && !it->empty(); ++it ) { //error1
8 *it1 = toupper(*it1);
9 }
10
11 vector<string> vstr{"aaa","bbb","ccc"};
13 for (auto it = vstr.begin(); it != vstr.end() && !it->empty(); ++it) {
14 *it = toupper(*it); //error2
15 }
Error1:第7行:expression must have pointer-to-class type
意思是:it->empty()这个表达式的i必须是要指向一个类的指针。it解引用后为char,是一个基本数据类型,不是类,也不存在有empty方法。
string在c++中可以是一个封装号的字符串类。
Error2:第14行:no instance of overloaded function "toupper" matches the argument list
toupper里面处理的是字符,而it = vstr.begin(), it指向的容器Vstr里面的第一个元素即字符串。
原文链接: https://www.cnblogs.com/y4247464/p/13807499.html
欢迎关注
微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍
原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/203897
非原创文章文中已经注明原地址,如有侵权,联系删除
关注公众号【高性能架构探索】,第一时间获取最新文章
转载文章受原作者版权保护。转载请注明原作者出处!