【发布时间】:2015-03-08 06:26:57
【问题描述】:
所以我的问题是我不知道如何将文本文件(其中包含用 Venus 2 编写的 1000 个逐行命令)正确输入到我试图重复创建的 while 循环中向电机发送位置命令。有一个文本文件,其中包含用 Venus 2 命令编写的坐标(鲜为人知的语言;使用起来很烦人)。我不是 c++ 计算机编程的狂热爱好者,但我知道大多数基本和中级 c++ 的理想。如果您有任何建议或cmets,请告诉我您的想法!
另外,这是文件的外观的 sn-p
0.0229 1 纳米 0.0317 2 纳米
0.0276 1 纳米 0.0311 2 纳米
0.0323 1 纳米 0.0302 2 纳米
0.0347 1 纳米 0.0310 2 纳米
0.0364 1 纳米 0.0310 2 纳米
0.0422 1 纳米 0.0343 2 纳米
0.0466 1 纳米 0.0324 2 纳米
位置、电机 ID、运动类型、位置、电机 ID、运动类型
(NI Pollux II 电机 x2)
//text file is opened
int i = 0;
double c1[1000];
char line;
cout << "Press any key to begin jitter.\n";
cin.get();
cout << "Running the jitter data...\n";
/* here there should be a conversion from double to char */
while (!jitterFile.eof()) {
jitterFile >> c1[i];
/* or here there should be a conversion */
if (serial.Open(18, 19200)){
static char szMessage[] = /* here is where the converted data should go */;
int nBytesSent = serial.SendData(szMessage, strlen(szMessage));
assert(nBytesSent == strlen(szMessage));
}
else{
cout << "error occurred with runJitter()...\n";
}
cout << c1[i] << endl;
++i;
}
//Sleep(1000);
jitterFile.close();
return 0;
}
【问题讨论】:
-
读取文件后是否需要双精度数组?
-
while (!jitterFile.eof())请先在这里彻底阅读:Why is iostream::eof inside a loop condition considered wrong?。char line;看起来也很可疑,你的意思是不是语义上更一致的东西,比如std::string line;
标签: c++ file char double typeconverter