
1 #include <iostream>
2 #include <fstream>
3 #include <cstdlib>
4 #include <string>
5 #include <vector>
6 #include <list>
7 using namespace std;
8
9 //vector<string> g_all;
10 //创建list存放数据
11 list<string> g_all;
12
13 //统计共有多少数据
14 int i = 0;
15
16 //载入内存
17 void loadmem()
18 {
19 //打开文件进行故去
20 ifstream fin("F:\\大数据\\大数据相关数据\\kaifang.txt");
21 //判断是否打开成功
22 if (!fin)
23 {
24 cout << "文件打开失败" << endl;
25 return;
26 }
27 //如果没有到文件末尾
28 while (!fin.eof())
29 {
30 //每次读取一行,并压入链表
31 char str[500]{ 0 };
32 fin.getline(str, 500);
33 string putstr;
34 putstr += str;//生成C++字符串
35 g_all.push_back(putstr);
36 i++;
37 }
38 cout << "成功载入内存,共有" << i << "个数据" << endl;
39 }
40
41 //遍历链表查询
42 void search()
43 {
44 while (1)
45 {
46 string str;
47 cin >> str;
48 for (auto i : g_all)
49 {
50 int pos = i.find(str, 0);
51 if (pos != -1)
52 {
53 cout << i << endl;
54 }
55 }
56 }
57 }
58
59
60 void main()
61 {
62 loadmem();
63 search();
64 cin.get();
65 }