Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/159.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
char*类型的值不能用于初始化类型为“的实体”;char"; 我是C++新手,我想做一些简单的事情,比如写磁盘到char内容[]/p>_C++_Char_Initialization_Entity - Fatal编程技术网

char*类型的值不能用于初始化类型为“的实体”;char"; 我是C++新手,我想做一些简单的事情,比如写磁盘到char内容[]/p>

char*类型的值不能用于初始化类型为“的实体”;char"; 我是C++新手,我想做一些简单的事情,比如写磁盘到char内容[]/p>,c++,char,initialization,entity,C++,Char,Initialization,Entity,我做这件事很艰难 这是我的密码: 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,

我做这件事很艰难

这是我的密码:

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数组(x)放入char列表中。正如错误消息所说。如果要将一个字符数组复制到另一个字符数组中,请参阅strcat函数系列


下一个错误涉及sizeof。它不计算字符串的长度。当您现在使用它时,它将给出一个4:缓冲区指针的大小。有一个strlen函数用于获取C字符串的长度

您希望
char buffer[]={x}
做什么?复制数组?好吧,让我修改我的示例以添加更多代码,不仅仅是x,还有3个变量。x、 请把你的例子变成一个真正的程序,它会给你这个错误。