一个简单的C++程序,最好帮忙运行一下

来源:百度知道 编辑:UC知道 时间:2024/07/01 05:05:17
#include<iostream.h> int main() {char a[3],b[]="china"; a=b; cout<<a<<endl; }用手机编的不知有没有错误。输出结果是多少,解释一下,答案是ch 感觉不太对

#include <iostream.h>
#include <string.h>
void main()
{
char a[3],b[]="china"; strcpy(a, b); cout<<a<<endl;
}

能够输出china,但是报错,是内存的问题,改为a[5]就OK了

明显是错的嘛 字符串不能用 =赋值的
用strcpy函数即可