📄 textchek.cpp
字号:
//: C03:Textchek.cpp
// From Thinking in C++, 2nd Edition
// at http://www.BruceEckel.com
// (c) Bruce Eckel 1999
// Copyright notice in Copyright.txt
// Counts words and lines in a text file.
// Ensures no line is wider than maxwidth.
#include <iostream>
#include <cstring> // strlen() & strtok()
using namespace std;
int main() {
// const means "you can't change it":
const int maxwidth = 64;
int linecount = 0;
int wordcount = 0;
char buf[100], c, trash;
while(cin.get(buf,100)) {
cin.get(trash); // Discard terminator
linecount++; // We just read a whole line
if(strtok(buf," \t")) {
wordcount++; // Count the first word
while(strtok(0," \t"))
wordcount++; // Count the rest
}
if(strlen(buf) > maxwidth)
cout << "line " << linecount
<< "is too long." << endl;
}
cout << "Lines: " << linecount << endl;
cout << "Words: " << wordcount << endl;
} ///:~
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -