当前位置: 首页 > news >正文

衡阳网站推广排名图片展示网站搭建

衡阳网站推广排名,图片展示网站搭建,请专业公司做个网站要花多少钱,设计软件需要多少钱注意#xff1a;本篇博客只是对上一篇博客功能的增加 1.创建配置文件(翻译) Dict.txt apple: 苹果 banana: 香蕉 cat: 猫 dog: 狗 book: 书 pen: 笔 happy: 快乐的 sad: 悲伤的 run: 跑 jump: 跳 teacher: 老师 student: 学生 car: 汽车 bus: 公交车 love: 爱 hate: 恨 hell…注意本篇博客只是对上一篇博客功能的增加 1.创建配置文件(翻译) Dict.txt apple: 苹果 banana: 香蕉 cat: 猫 dog: 狗 book: 书 pen: 笔 happy: 快乐的 sad: 悲伤的 run: 跑 jump: 跳 teacher: 老师 student: 学生 car: 汽车 bus: 公交车 love: 爱 hate: 恨 hello: 你好 goodbye: 再见 summer: 夏天 winter: 冬天 2.定义Dict类 #includestring #includefstream #includeunordered_map #includelog.hppclass Dict {//默认配置文件路径const std::string default_path ./Dict.txt;//默认分隔符const std::string sep : ; private://将配置文件的内容加载到_dict中bool Load(){std::ifstream file(_dict_conf_file_path);if(!file.is_open()){LOG(FATAL,open %s error,_dict_conf_file_path);return false;}//按行读取文件std::string line;while(getline(file,line)){if(line ) continue;std::string word;size_t pos line.find(sep);word line.substr(0,pos);std::string han;han line.substr(possep.size());//将对应的key value插入到哈希桶中_dict.insert(make_pair(word,han));LOG(DEBUG,load info %s: %s\n,word,han);}file.close();return true;} public:Dict(const std::string path ./Dict.txt):_dict_conf_file_path(path){Load();}std::string TranSlate(const std::string word){auto han _dict.find(word);if(han _dict.end()){return 这个单词未找到;}return han-second;}~Dict(){} private://key value 结构的字典 单词 翻译std::unordered_mapstd::string,std::string _dict;//配置文件的目录std::string _dict_conf_file_path; }; 3.main函数中将翻译模块和网络模块分开 //翻译模块Dict dict;//网络模块//智能指针创建UdpServerstd::unique_ptrUdpServer usvr std::make_uniqueUdpServer( port,std::bind(Dict::TranSlate,dict,std::placeholders::_1) ); //启动UdpServervoid Stat(){_running true;//服务器一般都是死循环while(true){sockaddr_in peer;//recvfrom的最后一个参数类型是socklen_tsocklen_t len sizeof(peer);char buffer[1024];//从接收缓存区中读取数据报int n recvfrom(_sockfd,buffer,sizeof(buffer)-1,0,(struct sockaddr*)peer,len);//读取到数据才做处理否则什么都不做if(n 0){buffer[n] 0;//打印是哪个客户端发来的消息InetAddr addr(peer);LOG(INFO,message form[%s:%d]: %s\n,addr.GetIp().c_str(),addr.Get_Port(),buffer);//将翻译发送给对方std::string response _func(buffer);sendto(_sockfd,response.c_str(),response.size(),0,(sockaddr*)peer,len);}}_running false;}
http://www.dnsts.com.cn/news/158363.html

相关文章:

  • 网站开发前端模板公司网站建设需要考虑什么问题
  • 做网站软件warhtml 好的网站
  • 网站改版用新空间好吗中小型公司网络设计方案
  • 网站标题的重要性网站营销公司
  • 芗城网站建设公司保定专业网站建设
  • 网站做端口是什么找人做网站怎么做
  • 微商网站如何做网站建设哪种语言好
  • 网泰网站建设网络seo是啥软件
  • 网站域名过期怎么办网站设计是什么意思
  • 网络安全设计方案黄骅seo
  • dede淘宝客网站国外红人营销网站
  • 物流企业网站wordpress footer错位
  • 重庆专业网站定制创建网站向导和模板
  • 网站建设新闻发布注意四川省住房和城乡建设厅网站首页
  • 临漳网站制作泰安网站建设找工作
  • 代发网站建设教程天津百度推广优化排名
  • 惠州外贸网站建设推广如何做好网站seo
  • 网站建设兼职劳务协议书如何建立微信小程序卖自己的产品
  • 汕头企业网站推广方法网站做百度收录的意义
  • 网站开发留言板廊坊网站建设企业
  • 捕鱼游戏网站建设步骤做网站交易装备可以么
  • 怎么制作网站程序从什么网站找做游戏的代码
  • 整站优化关键词排名餐饮网站建设案例
  • 加强政务门户网站建设大型网站设计方案
  • 樟树有哪几个网站做爆药库网站设计示例
  • 企业网站制作设wordpress add_user_meta
  • 环球资源网站什么时候做的专门做财经的网站
  • php网站开发多少钱oa办公系统网址
  • 做电销有什么资料网站北京cms建站系统
  • 画图标网站wordpress怎么安装到服务器配置