欧美大屁股bbbbxxxx,狼人大香伊蕉国产www亚洲,男ji大巴进入女人的视频小说,男人把ji大巴放进女人免费视频,免费情侣作爱视频

歡迎來(lái)到入門(mén)教程網(wǎng)!

C語(yǔ)言

當(dāng)前位置:主頁(yè) > 軟件編程 > C語(yǔ)言 >

C++多線程實(shí)現(xiàn)電子詞典

來(lái)源:本站原創(chuàng)|時(shí)間:2020-01-10|欄目:C語(yǔ)言|點(diǎn)擊: 次

本文實(shí)例為大家分享了C++多線程實(shí)現(xiàn)電子詞典的具體代碼,供大家參考,具體內(nèi)容如下

// Dictionary.cpp : 定義控制臺(tái)應(yīng)用程序的入口點(diǎn)。
//vs2013編譯
//字典文件:https://pan.baidu.com/s/1YHtwptaq_V8j034U9_J96A
#include "stdafx.h"
#include <string>
#include <vector>
#include <iostream>
#include <map>
#include <fstream>
#include <io.h>
#include <thread>
#include <time.h>
#include <Windows.h>
using namespace std;

class ParseDirectory
{
public:
 ParseDirectory(string path){
 this->path = path;
 getFiles(files);
 isdone = false;
 t = thread(&ParseDirectory::txtToDic, this);
 //t.join();
 }
 bool isDone()
 {
 return isdone;
 }
 map<string, string> getDic()
 {
 return vecDics;
 }
 virtual ~ParseDirectory()
 {

 }

private:
 vector<string> files;
 string path;
 thread t;
 map<string, string> vecDics;
 bool isdone;
 void getFiles(vector<string>& files)
 {
 //文件句柄
 long  hFile = 0;
 //文件信息
 struct _finddata_t fileinfo;
 string p;
 if ((hFile = _findfirst(p.assign(path).append("\\*").c_str(), &fileinfo)) != -1)
 {
  do
  {
  //如果是目錄,迭代之
  if ((fileinfo.attrib & _A_SUBDIR))
  {
   //if (strcmp(fileinfo.name, ".") != 0 && strcmp(fileinfo.name, "..") != 0)
   //getFiles(p.assign(path).append("\\").append(fileinfo.name), files);
   continue;
  }
  else
  {
   files.push_back(p.assign(path).append("\\").append(fileinfo.name));
  }
  } while (_findnext(hFile, &fileinfo) == 0);
  _findclose(hFile);
 }
 }
 void txtToDic()
 {
 for each (string file in files)
 {
  fstream f(file);
  string word, explain;
  //map<string, string> dic;
  
  if (f.is_open())
  {
  //cout << file << endl;
  while (1)
  {
   
   getline(f, word);
   if (!getline(f, explain))
   break;
   vecDics[word] = explain;
  }
  }
  f.close();
  //vecDics.push_back(dic);
 }
 
 //cout << vecDics.size() << endl;
 isdone = true;
 
 }
};
void setColor(unsigned short ForeColor = 2, unsigned short BackGroundColor = 0)

{

 HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);//獲取當(dāng)前窗口句柄

 SetConsoleTextAttribute(handle, ForeColor + BackGroundColor * 0x10);//設(shè)置顏色

}
int _tmain(int argc, _TCHAR* argv[])
{
 
 
 vector<ParseDirectory*> pds;
 cout << "正在加載資源...";
 long start = clock();
 vector<map<string, string> > allWords;
 for (int i = 0; i < 26; i++)
 {
 string name = ".\\";
 name += 'A' + i;
 pds.push_back(new ParseDirectory(name));
 }
 int cnt = 0;
 
 for (int i = 0; i < pds.size(); i++)
 {
 if (pds[i]->isDone())
 {
  cnt++;
  allWords.push_back(pds[i]->getDic());
  Sleep(300);
 }
 if (cnt == pds.size())
  break;
 }
 system("cls");
 cout << "加載完成!" << "耗時(shí):" << (clock()-start)/1000.0 << "s" << endl;
 cout << allWords.size();
 string inquir;
 while (1)
 {
 bool flag = false;
 setColor();
 cout << "\n輸入要查詢(xún)的單詞:";
 setColor(7, 0);
 cin >> inquir;
 for (int i = 0; i < allWords.size(); i++)
 {
  auto t = allWords[i][inquir];
  if (t.size())
  {
  
  cout << t << endl;
  flag=true;
  }
 }
 if (!flag)
 {
  setColor(4, 0);
  cout << "抱歉,未找到單詞" << endl;
 }
 }

 
 system("pause");
 return 0;
}

效果圖:

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持我們。

上一篇:C語(yǔ)言高效實(shí)現(xiàn)向量循環(huán)移位

欄    目:C語(yǔ)言

下一篇:C++單例類(lèi)模板詳解

本文標(biāo)題:C++多線程實(shí)現(xiàn)電子詞典

本文地址:http://mengdiqiu.com.cn/a1/Cyuyan/401.html

網(wǎng)頁(yè)制作CMS教程網(wǎng)絡(luò)編程軟件編程腳本語(yǔ)言數(shù)據(jù)庫(kù)服務(wù)器

如果侵犯了您的權(quán)利,請(qǐng)與我們聯(lián)系,我們將在24小時(shí)內(nèi)進(jìn)行處理、任何非本站因素導(dǎo)致的法律后果,本站均不負(fù)任何責(zé)任。

聯(lián)系QQ:835971066 | 郵箱:835971066#qq.com(#換成@)

Copyright © 2002-2020 腳本教程網(wǎng) 版權(quán)所有