首先
我發現這個東西根本不需要團隊合作啊..除了那個高級功能我完全不知道應該怎么做,雖然可能知道一點,但是因為GUI技術是在太太太,算了,就根本沒有所以難以實現
然后
先附上三個基本功能的函數:
// Count the chars num
int CharCount(char* filename)
{
int num = 0;
string s;
ifstream fp(filename);
if (!fp.is_open())
{
cout << "Error opening file" << endl;
exit(1);
}
while (getline(fp, s))
num += s.size();
fp.close();
return num;
}
//Count the words num
int WordCount(char* filename)
{
int num = 0;
string s, str;
ifstream fp(filename);
if (!fp.is_open())
{
cout << "Error opening file" << endl;
exit(1);
}
while (getline(fp, s))
{
istringstream ss(s);
while (ss >> str)
if(!(str[0]>='0' && str[0]<='9'))
num++;
}
fp.close();
return num;
}
//Count the lines num
int LineCount(char* filename)
{
int num = 0;
string s;
ifstream fp(filename);
if (!fp.is_open())
{
cout << "Error opening file" << endl;
exit(1);
}
while (getline(fp, s))
num++;
fp.close();
return num;
}
然后拓展功能懶得貼了,說一下主要思路
代碼行:字符大于1就可以了且如果含有注釋的話那就要更大一點
注釋行:如果含有//或者/的而且其他字符數量小于等于1*
空行:字符小于等于1即可
主函數:媽媽我會用命令行參數啦!!!
#include"functions.h"
int main(int argc, char* argv[])
{
if (argv[1][1] == 'c')
{
int num = CharCount(argv[2]);
cout << "Char nums is " << num << '\n' << endl;
}
else if (argv[1][1] == 'w')
{
int num = WordCount(argv[2]);
cout << "Word nums is " << num << '\n' << endl;
}
else if (argv[1][1] == 'l')
{
int num = LineCount(argv[2]);
cout << "Line nums is " << num << '\n' << endl;
}
else
cout << "Wrong Input!!!" << endl;
system("pause");
}