综述
这两个文件的组织还是比较相似的
其实就是字符串转换即可:
代码
float vertex[10000][3];
int surface[10000][3];
void read_off_file(string input)
{
/*函数说明:读取off文件
* */
char k;
int vertex_num;
int surface_num;
int other_num;
int i, j;
int s;
ifstream fin;
ofstream fout;
fin.open(input);
while (fin.fail())
{
cout << "Fail to open the file!" << endl;
exit(1);
}
fout.open("/Users/frankdura/Desktop/user/test.obj");
while (fout.fail())
{
cout << "Fail to open the fail!" << endl;
exit(1);
}
do
{
cout << fin.get();
} while (fin.get() != '\n');
fin >> vertex_num >> surface_num >> other_num;
cout << vertex_num;
for (i = 0; i < vertex_num; i++)
{
for (j = 0; j < 3; j++)
{
fin >> vertex[i][j];
}
}
for (i = 0; i < surface_num; i++)
{
fin >> s;
cout << s << endl;
for (j = 0; j < 3; j++)
{
fin >> surface[i][j];
}
}
for (i = 0; i < vertex_num; i++)
{
fout.put('v');
fout.put(' ');
for (j = 0; j < 3; j++)
{
fout << vertex[i][j];
fout.put(' ');
}
fout.put('\n');
}
fout.put('\n'); //注意控制换行
for (i = 0; i < surface_num; i++)
{
fout.put('f');
fout.put(' ');
for (j = 0; j < 3; j++)
{
fout << (surface[i][j] + 1);
fout.put(' ');
}
fout.put('\n');
}
fin.close();
fout.close();
cout <<"end" << endl;
}