首页 > 其他分享 >5.18

5.18

时间:2023-05-18 23:44:48浏览次数:37  
标签:std ifstream int 5.18 include inputFile

 1 #include <iostream>
 2 #include <fstream>
 3 #include <string>
 4 
 5 int main() {
 6     std::ifstream inputFile("D://article.txt"); 
 7 
 8     if (!inputFile) {
 9         std::cout << "无法打开输入文件!" << std::endl;
10         return 1;
11     }
12 
13     int wordCount = 0;
14     int lineCount = 0;
15     std::string line;
16 
17     while (std::getline(inputFile, line)) {
18         lineCount++; 
19 
20         
21         size_t pos = 0;
22         while ((pos = line.find_first_not_of(" \t", pos)) != std::string::npos) {
23             pos = line.find_first_of(" \t", pos + 1);
24             wordCount++;
25         }
26     }
27 
28     inputFile.close(); 
29 
30     std::cout << "文章中单词个数:" << wordCount << std::endl;
31     std::cout << "文章中行数:" << lineCount << std::endl;
32 
33     return 0;
34 }

 

标签:std,ifstream,int,5.18,include,inputFile
From: https://www.cnblogs.com/lijianlongCode13/p/17413641.html

相关文章

  • 5.18
    #include<iostream>usingnamespacestd;intmain(){      doublea;      double*p=&a;      cout<<"指针占了"<<sizeof(double)<<"字节"<<endl;      cout<<"指针所指向的变量占了"<<sizeof(p)&......
  • 编程一小时2023.5.18
    #include<iostream>#include<fstream>usingnamespacestd;classDog{public:intgetdogage(){returnage;}intgetdogweight(){returnweight;}voidsetdog(intx,inty){age=x;weight=y;}private:intage,weight;}; intmain(){intv1,v2;......
  • 5.18打卡
    一、实验内容定义一个Dog类,包括体重和年龄两个数据成员及其成员函数,声明一个实例dog1,体重5,年龄10,使用I/O流把dog1的状态写入磁盘文件。再声明一个实例dog2,通过读取文件dog1的状态赋给dog2。分别用文本方式和二进制方式操作文件。二、实验代码#include<bits/stdc++.h>usingna......
  • 5.18每日总结
    今日进行了python的学习。对于昨天的测试代码进行了分析学习。R7-1字典合并d1=eval(input())d2=eval(input())forkeyind2.keys():d1[key]=d1.get(key,0)+d2[key]t=list(d1.items())t.sort(key=lambdax:ord(x[0])iftype(x[0])==strelsex[0])......
  • 每日总结-23.5.18
    <%@pagelanguage="java"contentType="text/html;charset=UTF-8"pageEncoding="UTF-8"%><!DOCTYPEhtmlPUBLIC"-//W3C//DTDHTML4.01Transitional//EN""http://www.w3.org/TR/html4/loose.dtd&qu......
  • 5.18
    #include<iostream>usingnamespacestd;#include<string>classstudent{public:   voidshangke();protected:   stringname;   intbj;   intid;};classteacher{public:   voidjiaoke();protected:   intID;   intgz;};c......
  • 5.18总结
    packagecom.mf.jdbc.exmaple;importcom.alibaba.druid.pool.DruidDataSourceFactory;importcom.mf.jdbc.Brand;importorg.junit.Test;importjavax.sql.DataSource;importjava.io.FileInputStream;importjava.sql.Connection;importjava.sql.PreparedStatement;......
  • 5.18CSDN贪吃蛇
    贪吃蛇 速度不要调很慢会影响判断#include<iostream>#include<windows.h>#include<conio.h>#include<deque>#include<ctime>#include<stdexcept>usingnamespacestd;structSnake{//蛇类结构体charimage;shortx,y;//坐标};classsnakeGame......
  • 2023.5.18
    importosimportpandasaspd#添加测试数据os.makedirs(os.path.join('.','data'),exist_ok=True)data_file=os.path.join('.','data','house_tiny.csv')withopen(data_file,'w')asf:   f.write('N......
  • 5.18打卡
    一、问题描述:骰子是一个有六个面的正方体,每个面分别印有1~6之间的小圆点代表点数。假设这个游戏的规则是:两个人轮流掷骰子6次,并将每次投掷的点数累加起来。点数多者获胜;点数相同则为平局。要求编写程序模拟这个游戏的过程,并求出玩100盘之后谁是最终的获胜者。二、设计思路:由于每......