<<C++ Primer>> 第四版Exercise Section 8.4.1 练习题
2024-10-18 14:21:15
For exercise 8.6
// ConsoleApplication10.cpp : 定义控制台应用程序的入口点。
// #include "stdafx.h"
#include <iostream>
#include <fstream>
#include <sstream> using namespace std; void print(istream &in)
{
string str;
while (in >> str)
{
cout << str << endl;
}
} int main()
{
ifstream in("d://hello.txt");
print(in);
in.clear();
in.close();
return ;
}
For Exercise 8.7
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <sstream>
#include <vector> using namespace std; int main()
{
vector<string> vect;
vect.push_back("d://hello0.txt");
vect.push_back("d://hello.txt");
vect.push_back("d://hello1.txt");
vect.push_back("d://hello2.txt");
for (vector<string>::iterator begin = vect.begin(); begin != vect.end(); ++begin)
{
ifstream in;
in.open(begin->c_str());
if (!in)
{
cout << begin->c_str() << " does not exist in the system!!!" << endl; continue;
}
cout << "opening the file with name is: " << begin->c_str() << endl;
string str;
while (in >> str)
{
cout << str << endl;
}
in.clear();
in.close();
}
return ;
}
最新文章
- sublime 添加代码片段(snippets)
- hdu Is It A Tree?
- Java中sleep()和wait()的区别
- XCODE中的蓝色文件夹与黄色文件夹
- CocoaPods的安装[转载]
- windows下AppServ安装php的memcached扩展
- C#的委托 Action<;>;和Func<;>;
- td中使用overflow:hidden; 无效解决方案
- lc面试准备:Remove Duplicates from Sorted List II
- ExtJs5_继承自定义一个控件
- Webpack 2 视频教程 020 - Webpack 2 中的 HMR ( Hot Module Replacement )
- ES6的generator函数
- Docker学习笔记 - Docker的守护进程
- 解决python编码问题
- RESTful api风格介绍
- JIRA和Confluence更改JVM内存大小解决访问打开缓慢问题
- SQL Server清空日志以及查看日志大小语句
- sql 中常见的控制流语句
- table添加行
- CentOS工作内容(七)禁用IPV6