将文件名(图片名)写入txt文件

最近在学习pointnet,需要将点云的pcd文件名写入txt文件,然后需要会读取txt文件里的pcd文件制作dhf5文件,还需要将lable写入txt文件。

具体代码如下:

#include <fstream> 
#include <iostream>
#include <string>
#include <boost/format.hpp>
 
int write_string_to_file_append(const std::string & file_string, const std::string str )
{
	std::ofstream	OsWrite(file_string,std::ofstream::app);
	OsWrite<<str;
	OsWrite<<std::endl;
	OsWrite.close();
   return 0;
}
 
int main()
{
	boost::format f;
	std::string filename,lable0,lable1;
	int count = 0;
	
	while(1)
	{
		f = boost::format("%s%d%s") %"raw_data/test_pcd" %count %".pcd";
		filename = f.str();
		lable0 = "0";
		lable1 = "1";
		write_string_to_file_append(std::string("pcd_names_file1.txt"),filename);
		if(count < 249)
		{
			write_string_to_file_append(std::string("labels_file1.txt"),lable0);
		}
		else
		{
			write_string_to_file_append(std::string("labels_file1.txt"),lable1);
		}
		
		count ++;
		if(count > 708)
		{
			break;
		}
	}
	
	return 0;
}

编译方法如下即Makefile文件;

CC = g++
CFLAGS =  

#CC = aarch64-linux-gnu-g++
#CFLAGS = -L../../lib -lTTF_API -lvoxel -lusb-1.0 -std=c++11 -lti3dtof -lgomp -lc

STRIP = strip
INC =   

all : 
	$(CC) -c Read_write.cpp $(INC) $(CFLAGS)
	$(CC) -o Read_write Read_write.o $(INC) $(CFLAGS)  
	rm  Read_write.o

clean :
	rm -rf Read_write

这是在linux下进行运行的。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值