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

门户网站开发公司麒麟seo

门户网站开发公司,麒麟seo,做软件实施有前途吗,企业公司有哪些1.将File练习题&#xff0c;内部的FILE*描述符&#xff0c;改成int描述符 2。写一个类Fifo管道类。提高难度&#xff0c;什么都不提示。只要求&#xff1a;使用自己编写的Fifo类对象&#xff0c;实现2个终端之间互相聊天 file.cpp #include <iostream> #include <c…

1.将File练习题,内部的FILE*描述符,改成int描述符

2。写一个类Fifo管道类。提高难度,什么都不提示。只要求:使用自己编写的Fifo类对象,实现2个终端之间互相聊天

file.cpp

#include <iostream>
#include <cstring>
#include <cstdlib>
#include <unistd.h>
#include <sstream>
#include <vector>
#include <memory>
#include <head.h>
using namespace std;class File{
private:int fp;
public:File(){fp=open("./1.txt",O_RDWR);}~File(){close(fp);}void write(string str);void read();
};void File::write(string str){::write(fp,str.data(),str.size());cout<<"写入成功"<<endl;}
void File::read(){char buf[128]={0};lseek(fp,0,SEEK_SET);while(::read(fp,buf,sizeof(buf))>0){cout<<buf<<endl;memset(buf,0,128);}}
int main(int argc,const char** argv){File fp;string str="hello";fp.write(str);fp.read();return 0;
}

fifo1.cpp

#include <iostream>
#include <fstream>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <cstring>
#include <thread>#define FIFO_WRITE "fifo1"
#define FIFO_READ "fifo2"void readFromPipe() {mkfifo(FIFO_READ, 0666); // 创建FIFOint fd = open(FIFO_READ, O_RDONLY);if (fd == -1) {std::cerr << "Error opening " << FIFO_READ << " for reading" << std::endl;return;}char buffer[256];while (true) {memset(buffer, 0, sizeof(buffer));int bytesRead = read(fd, buffer, sizeof(buffer) - 1);if (bytesRead > 0) {buffer[bytesRead] = '\0'; // 确保字符串终止std::cout << "\n[Received]: " << buffer << "\n> ";std::cout.flush();}}close(fd);
}void writeToPipe() {mkfifo(FIFO_WRITE, 0666); // 创建FIFOint fd = open(FIFO_WRITE, O_WRONLY);if (fd == -1) {std::cerr << "Error opening " << FIFO_WRITE << " for writing" << std::endl;return;}std::string message;while (true) {std::cout << "> ";std::getline(std::cin, message);message += '\n'; // 添加换行符,确保 read 读取时能正确解析write(fd, message.c_str(), message.size());}close(fd);
}int main() {std::thread readThread(readFromPipe);std::thread writeThread(writeToPipe);readThread.join();writeThread.join();return 0;
}

fifo2.cpp

#include <iostream>
#include <fstream>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <cstring>
#include <thread>#define FIFO_WRITE "fifo2"
#define FIFO_READ "fifo1"void readFromPipe() {mkfifo(FIFO_READ, 0666);int fd = open(FIFO_READ, O_RDONLY);if (fd == -1) {std::cerr << "Error opening " << FIFO_READ << " for reading" << std::endl;return;}char buffer[256];while (true) {memset(buffer, 0, sizeof(buffer));int bytesRead = read(fd, buffer, sizeof(buffer) - 1);if (bytesRead > 0) {buffer[bytesRead] = '\0'; // 确保字符串终止std::cout << "\n[Received]: " << buffer << "\n> ";std::cout.flush();}}close(fd);
}void writeToPipe() {mkfifo(FIFO_WRITE, 0666);int fd = open(FIFO_WRITE, O_WRONLY);if (fd == -1) {std::cerr << "Error opening " << FIFO_WRITE << " for writing" << std::endl;return;}std::string message;while (true) {std::cout << "> ";std::getline(std::cin, message);message += '\n'; // 添加换行符,确保 read 读取时能正确解析write(fd, message.c_str(), message.size());}close(fd);
}int main() {std::thread readThread(readFromPipe);std::thread writeThread(writeToPipe);readThread.join();writeThread.join();return 0;
}


文章转载自:

http://528HDk68.tdfyj.cn
http://ULEaTfpf.tdfyj.cn
http://g5UbKjvv.tdfyj.cn
http://1uvOcGja.tdfyj.cn
http://FS1TE5Yu.tdfyj.cn
http://OoeINBWZ.tdfyj.cn
http://VewCSTB6.tdfyj.cn
http://Rm7LF7eE.tdfyj.cn
http://WrhyAI24.tdfyj.cn
http://xyaKmudX.tdfyj.cn
http://C7xIISZI.tdfyj.cn
http://1QW2QwOl.tdfyj.cn
http://SGKPZbie.tdfyj.cn
http://0X8GfWYQ.tdfyj.cn
http://eyPFGmTa.tdfyj.cn
http://9GcoDbO5.tdfyj.cn
http://LtFXqGlN.tdfyj.cn
http://vm8WncoC.tdfyj.cn
http://0LxmiCl2.tdfyj.cn
http://9bc4moot.tdfyj.cn
http://oQxrlRgt.tdfyj.cn
http://QCNpm9eL.tdfyj.cn
http://Hk0xxVsr.tdfyj.cn
http://F0FrLbWp.tdfyj.cn
http://6wQSSKL5.tdfyj.cn
http://OlZXKb4q.tdfyj.cn
http://NHk98hn4.tdfyj.cn
http://M3SImIkf.tdfyj.cn
http://h1q8WZSq.tdfyj.cn
http://mO8S2zQE.tdfyj.cn
http://www.dtcms.com/wzjs/669456.html

相关文章:

  • 做网站推广的话术平台设计是什么
  • 注册公司域名后如何做网站上海高端做网站
  • 开一个公司需要具备什么条件南京seo优化公司
  • 网站开发人员的短中长期目标诸城网站建设葛小燕
  • vue.js网站建设wordpress腾讯云cos插件
  • 浙江建设监理协会官方网站做兼职最好的网站
  • 哪家高端网站建设好网站开发技术难度
  • php 打开网站做旅游计划上哪个网站
  • c语言软件开和网站开发区别h5免费制作平台八图
  • 自己做电影网站违法专门做网站的公司
  • 息县网站建设wordpress的title设置
  • 南山网站制作北京市住房城乡建设门户网站
  • 后台网站更新 网站没显示中国企业500强各省数量
  • 上行2m可以做网站商城网站模板免费下载
  • net公司网站开发框架源代码wordpress 免费APP
  • 网站建设英文方案网站建设的电销
  • 云访客类似的网站识万物扫一扫
  • 做宣传海报的网站网站开发做什么科目
  • 网站建设成功案例书籍app开发公司图片
  • 网站换程序301注册推广赚钱一个80元
  • 磁力网站怎么做莆田网站建设外贸
  • 帮助做问卷调查的网站最正规二手手表平台
  • 如何选择邯郸网站建设怎么自己做免费网站
  • 网站判断手机跳转代码wordpress音乐盒
  • 注册网站的好处发软文在哪个网站找文章最好
  • 做网站要备案吗南溪门户网
  • 做网站自适应框架seo辉煌电商平台
  • 网站建设 猴王网络有实力公司简介模板300字
  • 郫县网站建设兼职wordpress手机端网站模板下载
  • 做博客网站要什么技术黄页88官网登录