c/c++ .c/.cpp

来源:百度知道 编辑:UC知道 时间:2024/05/27 02:18:52
#include <stdio.h>
void main()
{
struct st{
int s[4];int b;

}stu={"好",1,34};
printf("%c",stu.s);

}当是.c时可以运行,但是...cpp时就说有错不能运行?是怎么回事?谢

你好:

(1)你想把“好"赋给S,那么你最好结构体里改成ch s[4];因为字符数组用来存放字符串的,而不能用int型的数组来存放

(2)把printf("%c",stu.s); 相应的改成printf("%s",stu.s);

(3).cpp后缀表示的是c++的程序,而你的头文件#include <stdio.h> 就应该改成 #include <iostream>

祝你好运!

出错提示写上来啊...