首页 > 代码库 > <<C++ Primer>> 第四版Exercise Section 8.4.1 练习题
<<C++ Primer>> 第四版Exercise Section 8.4.1 练习题
For exercise 8.6
1 // ConsoleApplication10.cpp : 定义控制台应用程序的入口点。 2 // 3 4 #include "stdafx.h" 5 #include <iostream> 6 #include <fstream> 7 #include <sstream> 8 9 using namespace std; 10 11 12 void print(istream &in) 13 { 14 string str; 15 while (in >> str) 16 { 17 cout << str << endl; 18 } 19 } 20 21 int main() 22 { 23 ifstream in("d://hello.txt"); 24 print(in); 25 in.clear(); 26 in.close(); 27 return 0; 28 }
For Exercise 8.7
1 #include "stdafx.h" 2 #include <iostream> 3 #include <fstream> 4 #include <sstream> 5 #include <vector> 6 7 using namespace std; 8 9 int main() 10 { 11 vector<string> vect; 12 vect.push_back("d://hello0.txt"); 13 vect.push_back("d://hello.txt"); 14 vect.push_back("d://hello1.txt"); 15 vect.push_back("d://hello2.txt"); 16 for (vector<string>::iterator begin = vect.begin(); begin != vect.end(); ++begin) 17 { 18 ifstream in; 19 in.open(begin->c_str()); 20 if (!in) 21 { 22 cout << begin->c_str() << " does not exist in the system!!!" << endl; 23 24 continue; 25 } 26 cout << "opening the file with name is: " << begin->c_str() << endl; 27 string str; 28 while (in >> str) 29 { 30 cout << str << endl; 31 } 32 in.clear(); 33 in.close(); 34 } 35 return 0; 36 }
<<C++ Primer>> 第四版Exercise Section 8.4.1 练习题
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。