C++ 读写代码

fgets:获取N个字符,这里是128,或者遇到\n结束,存入l_chANames中。
fopen:输入路径是char*类型

    #include <sdtio>
	std::map<std::string, vector<int>> Lables;
	std::vector<std::string> labels_list;
	FILE *pFile = fopen(label_file.c_str(), "r");
	bool bRet;
	char l_chANames[128];
	do
	{
		bRet = (fgets(l_chANames, 100, pFile) != NULL);
		std::string lstrTemp = l_chANames;
		if (lstrTemp.size() > 1)
		{
			l_chANames[lstrTemp.size() - 1] = '\0';
			labels_list.push_back(l_chANames);
			Lables[l_chANames] = {0, 0};
		}
	} while (bRet);
	fclose(pFile);	

文件拷贝:
需要头文件

#include <unistd.h>
#include <fcntl.h>

unistd包含:read,write
fcntl包含: open

fd= open(src_path.c_str(),O_RDWR|O_CREAT);
fd2 = open(des_path.c_str(),O_RDWR|O_CREAT);
while(len = read(fd,buff,1024))
{
  	write(fd2,buff,len);
}
close(fd);
close(fd2); 

在这里插入图片描述在这里插入图片描述

https://blog.csdn.net/qq_21197941/article/details/125168151?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522166797400516782425619539%2522%252C%2522scm%2522%253A%252220140713.130102334…%2522%257D&request_id=166797400516782425619539&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2allbaidu_landing_v2~default-1-125168151-null-null.142v63wechat,201v3control,213v2t3_esquery_v2&utm_term=c%2B%2B%20O_RDWR&spm=1018.2226.3001.4187

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值