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

📄 main9_5.cpp

📁 C++ PRIME书中的原代码,看本书时可以学习的例子.
💻 CPP
字号:
// Section 7.9.5
// $ CC compare.cpp sort.cpp main9_5.cpp

/*
	a
        drizzle
        falling
        left
        light
        museum
        the
        they
        was
        when
*/

#include <iostream>
using std::cout;

#include <string>
using std::string;

// defined in compare.C 
int lexicoCompare( const string &, const string & );
int sizeCompare( const string &, const string & );

typedef int (*PFI)( const string &, const string & );
// defined in sort.C
void sort( string *, string *, PFI=lexicoCompare );

string as[10] = { "a", "light", "drizzle", "was", "falling",
                  "when", "they", "left", "the", "museum" };

int main() {
	// call sort() which uses the default argument for compare
	sort( as, as + sizeof(as)/sizeof(as[0]) - 1 );

	// display the result of the sorted array
	for ( int i = 0; i < sizeof(as)/sizeof(as[0]); ++i )
		cout << "\t" << as[ i ].c_str() << "\n";
}

⌨️ 快捷键说明

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