?? cmpiter.cpp
字號:
//: C01:CmpIter.cpp
// From Thinking in C++, 2nd Edition
// Available at http://www.BruceEckel.com
// (c) Bruce Eckel 2000
// Copyright notice in Copyright.txt
// Find a group of characters in a string
#include <string>
#include <iostream>
using namespace std;
// Case insensitive compare function:
int
stringCmpi(const string& s1, const string& s2) {
// Select the first element of each string:
string::const_iterator
p1 = s1.begin(), p2 = s2.begin();
// Don't run past the end:
while(p1 != s1.end() && p2 != s2.end()) {
// Compare upper-cased chars:
if(toupper(*p1) != toupper(*p2))
// Report which was lexically greater:
return (toupper(*p1)<toupper(*p2))? -1 : 1;
p1++;
p2++;
}
// If they match up to the detected eos, say
// which was longer. Return 0 if the same.
return(s2.size() - s1.size());
}
int main() {
string s1("Mozart");
string s2("Modigliani");
cout << stringCmpi(s1, s2) << endl;
} ///:~
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -