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
. Thanks.
You are trying to cast the char array name
into a single char, this won't work, these types are incompatible.
If you want to use the content of name
, you should use:
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:
/* 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. Use char *variable
instead:
char *variable = (*no).datbase.name;
cout<< variable << endl;
if you want to print just one char
acter, write:
char variable = (*no).datbase.name[0]; //the first character of 'name'
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.