《C++ Primer》8.2.1节练习(部分)
生活随笔
收集整理的這篇文章主要介紹了
《C++ Primer》8.2.1节练习(部分)
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
練習(xí)8.4:
#include <iostream> #include <fstream> #include <string> #include <vector> using namespace std;int main() {//打開文件ifstream in("D:\\CCCCCCCCCCCCCCCCCCC\\yyhaif.txt");if (!in) {cerr << "無法打開輸入文件" << endl;return -1;}string line;vector<string>words;while (getline(in, line)) {words.push_back(line);}in.close();//輸入完畢,關(guān)閉文件vector<string>::const_iterator it = words.begin();while (it != words.end()) {cout << *it << endl;++it;} }練習(xí)8.5:
#include <iostream> #include <fstream> #include <string> #include <vector> using namespace std;int main() {//打開文件ifstream in("D:\\CCCCCCCCCCCCCCCCCCC\\yyhaif.txt");if (!in) {cerr << "無法打開輸入文件" << endl;return -1;}string line;vector<string>words;while (in >> line) {words.push_back(line);}in.close();//輸入完畢,關(guān)閉文件vector<string>::const_iterator it = words.begin();while (it != words.end()) {cout << *it << endl;++it;} }練習(xí)8.6:
暫時(shí)不會(huì)!!!
總結(jié)
以上是生活随笔為你收集整理的《C++ Primer》8.2.1节练习(部分)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 解决Aero特效无法显示问题
- 下一篇: 《C++ Primer》8.3.1节练习