【发布时间】:2014-06-17 00:40:19
【问题描述】:
我是 C++ 新手,我想做一些简单的事情,例如将 char[] 的内容写入磁盘
我很难做到。
这是我的代码:
char x[256],y[256],z[256];
sprintf( x, "%.2f", pCommandHandling->m_dtHandleInformation[i].Xfrms.translation.x ); //pCommandHandling->m_dtHandleInformation[i].Xfrms.translation.x is a float struct
sprintf( y, "%.2f", pCommandHandling->m_dtHandleInformation[i].Xfrms.translation.y ); //pCommandHandling->m_dtHandleInformation[i].Xfrms.translation.y is a float struct
sprintf( z, "%.2f", pCommandHandling->m_dtHandleInformation[i].Xfrms.translation.z ); //pCommandHandling->m_dtHandleInformation[i].Xfrms.translation.z is a float struct
FILE *tracker_file = fopen("NDI_FiMe.TMP","w");
char buffer[] = {x,";",y,";",z};
fwrite(buffer , sizeof(char), sizeof(buffer), tracker_file);
fclose(tracker_file);
我遇到的问题是:
IntelliSense:“char *”类型的值不能用于初始化“char”类型的实体
【问题讨论】:
-
你想让
char buffer[] = {x}做什么?复制数组? -
好吧,让我修改我的示例以添加更多代码,不仅仅是x,还有3个变量。 x、y 和 z
-
请让你的例子成为一个真正给你错误的真实程序。 stackoverflow.com/help/mcve
标签: c++ char initialization entity