2019.12.12
一、essential c++
1.练习1.8(没有做好)
#include <iostream>
#include <fstream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
int main()
{
ifstream
in_file("C:\Users\chenyiqun\Desktop\\cache.txt");
if (! in_file)
{
cerr << "不能打开文件";
return -1;
}
ofstream
out_file("C:\Users\chenyiqun\Desktop\\cache.txt");
if (!out_file)
{
cerr << "不能打开文件2";
return -2;
}
string word;
vector<string> text;
while
(in_file >> word)
text.push_back(word);
int i;
cout << "unsorted text:\n";
for (i = 0;
i < text.size(); i++)
cout << text[i] << ' ';
cout << endl;
sort(text.begin(), text.end());
out_file << "sorted text:\n";
for (i = 0;
i < text.size(); i++)
out_file << text[i] << ' ';
out_file << endl;
return 0;
}
2.练习1.8