[英]invalid conversion from ‘char*’ to ‘char’ [-fpermissive] How to print?? But inside the variable
struct student{
char name[30]...
};
struct element
{
struct element *ant;
struct student databse;
struct element *prox;
};
Element *no = *pointer_to_pointer;
cout<< (*no).datbase.name << endl;
I printed the name correctly.我正确地打印了名称。
Element *no = *pointer_to_pointer;
char variable = (*no).datbase.name;
cout<< variable << endl;
Error.错误。 Why?为什么? How to print?如何打印? But inside the variable
.但是在variable
里面。 Thanks.谢谢。
You are trying to cast the char array name
into a single char, this won't work, these types are incompatible.您正在尝试将 char 数组name
转换为单个 char,这不起作用,这些类型不兼容。
If you want to use the content of name
, you should use:如果你想使用name
的内容,你应该使用:
const char* variable = (*no).datbase.name;
std::cout << variable << std::endl;
If you want to index inside the name
char array, use []
to index it, like this:如果要在name
char 数组中进行索引,请使用[]
对其进行索引,如下所示:
/* Take first character of name */
char variable = (*no).datbase.name[0];
std::cout << variable << std::endl;
The type of datbase.name
is char[]
, which means you can not assign it to a char
variable directly. datbase.name
的类型是char[]
,这意味着您不能直接将其分配给char
变量。 Use char *variable
instead:使用char *variable
代替:
char *variable = (*no).datbase.name;
cout<< variable << endl;
if you want to print just one char
acter, write:如果您只想打印一个char
,请编写:
char variable = (*no).datbase.name[0]; //the first character of 'name'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.