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

📄 io20_2_1.04.c

📁 C++ Primer的第三版结合了Stanley Lippman的实践经验和Josée Lajoie对于ANSI/ISO标准C++的深入理解。这本指导书的第三版已经被重新改写过
💻 C
字号:
// #include <iostream>

#include <iostream.h>
#include <string>

/**
 **
 stanl@john: d.ch20 261 : a.out < alice_emma

 The number of words read is 65
 The longest word has a length of 10
 The longest word is creature,"

 **
 **/

int main()
{
	string buf, largest;

	// hold statistics;
	int curLen,   // length of current word
	    max = -1, // maximum word length
	    cnt = 0;  // count of words read

	while ( cin >> buf ) 
	{
 		curLen = buf.size();
 		++cnt;

 		// new longest word? save it.
 		if ( curLen > max ) 
		{
 			max = curLen;
 			largest = buf;
 		}
	}

	cout << "The number of words read is " << cnt << endl;
	cout << "The longest word has a length of " << max << endl;
	cout << "The longest word is " << largest << endl;
}

⌨️ 快捷键说明

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