//练习8.4 编写函数,以读模式打开一个文件,将其内容读入到一个string的vector中,
//将每一行作为一个独立的元素存于vector中,改写上面的程序,将每个单词作为一个独立的元素进行存储
#include<iostream>
#include<string>
#include<sstream>
#include<vector>
#include<fstream>
using namespace std;
int main(int argc, char *argv[])
{
ifstream fs;
fs.open("text.txt",ifstream::in);//创建一个输入文件流对象,并以读的形式打开
vector <string> lines1,lines2;
string line,word;
while (getline(fs,line))
{
cout << line;//getline 会自动舍弃换行符,凡是空格会留着
lines1.push_back(line);
istringstream ss(line);
while (ss >> word)
{
lines2.push_back(word);
}
}
for (vector<string>::iterator it = lines1.begin(); it != lines1.end(); ++it)
{
cout << *it << endl;
}
cout << "lines printing finishes!" << endl;
for (vector<string>::iterator it = lines2.begin(); it != lines2.end(); ++it)
{
cout << *it << endl;
}
cout << "lines printing finishes!" << endl;
system("pause");
return 0;
}相关推荐
13 万字 C 语言从入门到精通保姆级教程2021 年版
13 万字C语言保姆级教程,从入门到精通。
Go 语言圣经 8.4 Channels
8.4 Channels 知识点 1.goroutine是Go语言程序的并发体的话,channels则是它们之间的通信机制 2.一个channel是一个通信机制,它可以让一个goroutine通过它给另一个goroutine发送值信息 3.channel的零值也是nil 4.两个相同类型的channel可以使用==运算符比较,同样可以和nil比较 5.channel有发送和接受两个主要...
双系统下 ubuntu 20.04 突然 开机黑屏报错 hdaudioC0D2: unable to configure disabling
今天在开实验室开双系统台式机时,ubuntu 20.04 系统下,突然在某次关机后再开机时,本来启动好好的,但是在进行图形化启动时,本来应该是显示输入账号和密码时,直接黑屏报错了,内容为 hdaudioC0D2: unable to configure disabling ,这里是记录了报错的解决全过程
C++Primer第五版 8.2.1节练习
练习8.4:编写函数,以读模式打开一个文件,将其内容读入到一个string的vector中,将每一行作为一个独立的元素存于vector中。 答:见 练习8.4.cpp练习8.5:重写上面的程序,将每个单词作为独立的元素进行存储。 答:见 练习8.5.cpp练习8.6:重写7.1.1节书店程序(第229页),从一个文件中读取交易记录。将文件名作为一个参数传递给main(参见6.2.5节,第196页
非易失存储器读写
24C256、IIC_SCL、IIC_SDA
【实战指南】基于YOLOv11的肺结节检测系统开发与优化(LUNA2016数据集)
本文提供了基于YOLOv11模型和LUNA2016数据集开发肺结节检测系统的完整实战指南。详细介绍了从环境搭建、数据预处理、模型训练与优化,到构建Web应用系统的全流程,旨在帮助开发者快速掌握医疗影像AI项目的核心开发技能。
决策树
机器学习---1 分类篇决策树1. summary2.主要流程3. 核心问题3.1 如何决定测试条件的分配3.2 贪心的策略:总结3.2.1 GINI3.2.2Entropy3.2.3 Misclassification error何时停止划分结点? 决策树 1. summary 优点: 1.计算复杂度不高 2.输出结果易于结束, 3.对中间值不敏感,可以处理不相关特征数据 缺点:易产生过拟合现象 适用数据类型:数值型和标称型 2.主要流程 1: 收集数据
5、数据计算与处理技巧全解析
本文深入解析了Tableau中的多种数据计算与处理技巧,涵盖LOD计算、日期与字符串处理、计数优化、数据混合限制及自定义总计等核心内容。通过实际案例和流程图,系统讲解了各技巧的应用场景、实现步骤与注意事项,并提供性能优化建议和常见问题解答,帮助用户提升数据分析效率与可视化精度。同时展望了未来数据计算技术的发展趋势,是Tableau用户进阶必备的全面指南。
C++ primer(第五版) 练习 8.4 个人 code
C++ primer(第五版) 练习 8.4 题目:编写函数,以读模式打开一个文件,将其内容读入到一个string的vector中 将每一行作为一个猖的元素存于vector中。 答:
Android SystemUI——初始化流程(三)
1、Android 系统在启动之后,首先会Zygote进程,Zygote进程又会进一步启动 SystemServer进程,它会启动各种系统所需要的服务,在监听AMS启动完毕之后,还会启动SystemUIService。2、在启动SystemUIService服务之前,系统首先会创建SystemUI对应的进程,获取SystemUIAppComponentFactory实例对象,调用instantiateApplicationCompat创建SystemUIApplication实例对象并设置回调方法。
WIFI和BT测试(射频工程师)
买不了吃亏买不了上当,我卖的是技能,你收获的是经验。
习题8.4
输入某班某门课的成绩(最多不超过40人,具体人数由用户键盘输入),用函数编程统计不及格人数。#include<stdio.h> #define N 40 int main() { int a[N],i,n,count=0; printf("请输入学生人数:"); scanf("%d",&n); for(i=0;i<n;i++) { printf("请输入学生成绩:"
使用安卓的IMU数据进行 行人航位推算(PDR)推算步长 附python 代码
加速度计数据、陀螺仪数据、重力传感器数据、姿态仰角数据。数据分析与定位轨迹生成主要使用Python离线完成。示意图。
python编程:从入门到实践练习8-3,8-4,8-5
# 8-3 T恤 : 编写一个名为make_shirt() 的函数, 它接受一个尺码以及要印到T恤上的字样。 # 这个函数应打印一个句子, 概要地说明T恤的尺码和字样。 # 使用位置实参调用这个函数来制作一件T恤; 再使用关键字实参来调用这个函数。 def make_shirt(size='XL',word='I love python'): print("这件T恤的尺码是 "+size+" !") print("T恤正面印有 "+word+" 的字样") make_shirt() #
深度学习工具包 DeepLearningToolbox
深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[](https://bitdeli.com/free "Bitdeli Badge")
ET2012新版免狗免安装绿色软件
ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,
如何备考2025年AMC8竞赛?吃透2000-2024年600道真题(免费送题)
2025年1月的AMC8还有9个多月,但是准备却要尽早进行。我整理了2000-2004年的全部AMC8真题(完整版共600道,且修正了原试卷中的少量bug),并且独家制作成多种在线练习,利用碎片化时间,8个多月的时间足以通过自学在2025年AMC8竞赛中取得好成绩。详情见文末。我们继续来随机看五道AMC8的真题和解析,根据实践经验,对于想了解或者加AMC8美国数学竞赛的考生来说,吃透AMC8历年真题是备考更加科学、有效的方法之一。
Statistics and Machine Learning Toolbox
Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具
Python第八章作业07
【代码】Python第八章作业07。
jre9下载 jdk9
(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】
高效备考2025年AMC8数学竞赛:2000-2024年AMC8真题练一练
如何提高小学和初中数学成绩?小学和初中可以参加的数学竞赛有哪些?不妨了解一下AMC8美国数学竞赛,现在许多小学生和初中生都在参加这个比赛。如果孩子有兴趣,有余力的话可以系统研究AMC8的历年真题,即使不参加AMC8竞赛,如果吃透了历年真题600道和背后的知识体系,那么小学和初中数学一定会学得非常轻松、游刃有余。今天我们继续来随机看五道AMC8的真题和解析,对于想了解或者加AMC8美国数学竞赛的孩子来说,吃透AMC8历年真题是备考最科学、最有效的方法之一。
mysql练习题-燕十八老师
不错的练习题
搜索与回溯小练习1
1.素数环:从1到20这20个数摆成一个环,要求相邻的两个数的和是一个素数。 #include<cstdio> #include<iostream> #include<cstdlib> #include<cmath> using namespace std; bool b[21]={0}; int total=0,a[21]={0}; int sea...
IS 203 Exercise Set 5Haskell
Part 13 & 4MondayPart 2TuesdayPart 32 & 3WednesdayPart 4ThursdayPart 52 & 3FridayPart 66. Fa 4 EI6. Ga 4 EI9. ∃x¬Gx88. Fa。
11.11 练习
11–1.参数。比较下面 3 个函数: def countToFour1(): for eachNum in range(5): print eachNum, def countToFour2(n): for eachNum in range(n, 5): print eachNum, def ...
2.20练习错题
i的初始值为0,i--结果-1,i为整形,sizeof(i)求i类型大小是4,按照此分析来看,结果应该选择B,但是sizeof的返回值类型实际为无符号整形,因此编译器会自动将左侧i自动转换为无符号整形的数据,-1对应的无符号整形是一个非常大的数字,超过4或者8,故实际应该选择A。int占4个字节,指针表示地址空间个数,总共有2^32个,故占4个字节。C.32位下:4,4,2^32 64位下:4,8,2^64。D.32位下:4,4,2^32 64位下:4,4,2^64。五、计算一个数的每位之和(递归实现)
第八章作业
【代码】第八章作业。
扣扣位数限制(练习)
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>Document</title></head><body> 账号:<input type="text" id="a"> <br> <input type="submit" id="c" value="登录"> <script>
python核心编程--第十章 11.11 练习
#!/usr/bin/python # -*- coding: utf-8 -*- # 11-3 函数。在这个练习中,我们将实现max()和min()内建函数。 # (a) 写分别带两个元素返回一个较大和较小元素,简单的max2()核min2()函数。 # 他们应该可以用任意的python 对象运作。举例来说,max2(4,8)和min2(4,8)会各自每次返回8 和4。 # (b
mysql练习
答:1.可以用float(m,n)(浮点类型)、double(m,n)和decimal(m,n)(定点类型)来表示。2. 共通:浮点类型和定点类型在插入超过标度的值的时候,都会进行四舍五入使值在安全范围内。不同点:(1).浮点类型在插入超过标度的值时不会报警,而定点类型会进行截断警告,且浮点类型在未指定精度时会按实际的精度去进行存放,而定点类型在未指定精度时会按(10,0)去进行存放。(2).浮点类型在长度一定的情况下可以表示的数据范围更大,而定点类型精度更高。
61万+



被折叠的 条评论
为什么被折叠?



