练习2-4:编一个程序统计文件中特定单词出现的次数(要求使用string类的运算符==来查找单词)

    技术2022-05-19  29

    #include<iostream>#include<string>#include<fstream>using namespace std;

     

    void main(){ ifstream in("e://test.txt"); string word; int num = 0; while(in>>word) {  if(word=="hello")  {   num++;  } } cout<<"hello 出现的次数为:"<<num<<endl;}


    最新回复(0)