-
- #include <iostream>
- #include <string>
- #include <vector>
- #include <fstream>
- using namespace std;
- int main()
- {
- ifstream infile;
- string word;
- string in_file = "txt.txt";
- vector<char> char_vec;
- int count=0; ;//记数
- infile.open( in_file.c_str() );
- if ( ! infile ) {
- cerr << "error: unable to open input file!/n";
- return -1;
- }
- while ( infile >> word )
- {
- count++;
- }
- return 0;
- }
- int WordNum(char str[])
- {
- int i,flag,count;
- flag = 0;
- count = 0;
- for(i = 0; str[i]!='/0'; i++)
- {
- if(str[i] == ' ')
- flag = 0;
- else if(flag == 0)
- {
- flag = 1;
- count++;
- }
- }
- return count;
- }
- /*统计字符串中汉字个数*/
- int HanZiNum(char str[])
- {
- int i,count;
- count = 0;
- for(i = 0; str[i] != '/0'; i++)
- {
- if(!(str[i] >= 0 && str[i] <= 255))
- count++;
- }
- return count/2;
- }
vc 统计单词个数
最新推荐文章于 2021-03-25 20:32:45 发布