السلام عليكم
لدي ملف من الشكل
-0.01 0.03 0.04 -0.5 0.6 0.8 0.3 -0.005 -0.003 -0.008 -0.03 0.05 0.06 -0.005 -0.2 0.3 0.8 1.02 1.03 1.04 .........................
اريد قراءته و حفظه في struct
struct Vector3
{
float x, y, z;
};
struct pose
{
int time;
Vector3 joint_angle;
};بحيث كل سطر يبدا برقم float time ثم كل 3 ارقام فيما بعد نضعها في joint_angle
و السطر كله عبارة عت pose
للتوضيح
اقتباس-0.01 is pose[0].time , 0.03 0.04 -0.5 is pose[0].joint_angle[0]........-0.03 is pose[1].time ,0.05 0.06 -0.005 is pose[1].joint_angle[0]...
عملت كود صغير
struct joint_angle
{
int count;
Vector3 orient;
};
//////////////////////////////
struct pose
{
float time;
std::vector<joint_angle> angle;
};
////////////////////////////
std::istream & operator>> (std::istream & stream, joint_angle & ja)
{
ja.count = 0;
stream >> ja.orient.x >> ja.orient.y >> ja.orient.z;
printf ("ja.orient.x===>%f",ja.orient.x);
printf ("ja.orient.y===>%f",ja.orient.y);
printf ("ja.orient.z===>%f",ja.orient.z);
return stream;
}////////////////////////////////////////////
int main()
{
std::ifstream stream("angle.txt" );
joint_angle ja;
std::vector<joint_angle> angles;
char c;
while ( stream >> ja >> std::noskipws >> c ) {
printf ("ja.orient.x===>%f",ja.orient.x);
printf ("ja.orient.y===>%f",ja.orient.y);
printf ("ja.orient.z===>%f",ja.orient.z);
angles.push_back(ja);
if (c == '\n' ) {
stream >> std::skipws; // Reset - because of the reading we have to repeat (see 1)
// new pose incoming
// possibly break; here
}
}
//}
return 0;
}لكن المشكلة انو يقرا لي الاربعة ارقام الاولى فقط لا يقرا لي الباقي
اظن ان المشكلة هنا
std::ifstream stream("angle.txt" );ارجو منكم مساعدتي