⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cmpiter.cpp

📁 Think in C++ 第二版源码
💻 CPP
字号:
//: C17:CmpIter.cpp

// From Thinking in C++, 2nd Edition

// Available at http://www.BruceEckel.com

// (c) Bruce Eckel 1999

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

} ///:~

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -