c++计算txt点云文档中点的个数计算结果为0,请问是什么问题
#include<iostream>
#include<fstream>
#include<vector>
int main()
{
//打开点云数据文件
std::ifstream in_file("传送带上的碗.txt");
//定义用于存储点云数据的向量
std::vector<float>points;
//如果文件打开成功
if (in_file.is_open())
{
float x, y, z;
//逐行读取文件中的点
while (in_file >> x >> y >> z)
{
//将点添加到向量中
points.push_back(x);
points.push_back(y);
points.push_back(z);
}
//关闭文件
in_file.close();
//计算点的数量
int num_points = points.size() / 3;
//输出读取的点的数量
std::cout << "number of points " << num_points << " points." << std::endl;
}
else
{
std::cerr << "Filed to open file." << std::endl;
}
return 0;
}
19行的输入需要空白字符分隔。你的文件里是逗号分隔的。需要单独处理逗号
void Encode(char* data,HuffmanCode HC,int length)
{
ofstream outfile;
outfile.open("code.txt");
for(int i = 0;i < strlen(data);++i) // 依次读入数据,查找对应的编码,写入编码文件
{
for(int j = 1;j <= length;++j)
{
if(data[i] == HC[j].data)
{
outfile<<HC[j].str;
}
}
}
outfile.close();
cout<<"the code txt has been written"<<endl;
cout<<endl;
}