<> 第四版Exercise Section 8.4.1 练习题

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 ;
}
上一篇:买卖股票的最佳时机含手续费


下一篇:AUTOSAR-MemIf模块