c++题目求解
#include<iostream.h>classX{inta;char*b;floatc;public:X():b("X::X(1)"),a(3),c(10){cout...
#include <iostream.h>
class X{
int a; char *b; float c;
public:
X():b("X::X(1)"),a(3),c(10){
cout<<"a="<<a<<",b="<<b<<",c="<<c<<endl; }
X(int x1,char *x2,float x3):c(x3),a(x1){
b=new char[sizeof(x2)+1]; strcpy(b,x2);
cout<<"a="<<a<<",b="<<b<<",c="<<c<<endl; }
X(int x1,char*x2="X::X(2)",int x3=20):b(x2),c(x3),a(x1){
cout<<"a="<<a<<",b="<<b<<",c="<<c<<endl; }
X(X& other){
a=other.a+100; b="X::X(3)" ; c=other.c;
cout<<"a="<<a<<",b="<<b<<",c="<<c<<endl; } };
void main(){
X *A=new X(4,"X::X(4)",32);
X B,C(10),D(B);
}
要求写出程序的输出结果,用序号标出输出顺序
但是我把这些代码打进VC++6.0里无法运行,加了头文件#include <string.h>还是无法运行
为什么? 展开
class X{
int a; char *b; float c;
public:
X():b("X::X(1)"),a(3),c(10){
cout<<"a="<<a<<",b="<<b<<",c="<<c<<endl; }
X(int x1,char *x2,float x3):c(x3),a(x1){
b=new char[sizeof(x2)+1]; strcpy(b,x2);
cout<<"a="<<a<<",b="<<b<<",c="<<c<<endl; }
X(int x1,char*x2="X::X(2)",int x3=20):b(x2),c(x3),a(x1){
cout<<"a="<<a<<",b="<<b<<",c="<<c<<endl; }
X(X& other){
a=other.a+100; b="X::X(3)" ; c=other.c;
cout<<"a="<<a<<",b="<<b<<",c="<<c<<endl; } };
void main(){
X *A=new X(4,"X::X(4)",32);
X B,C(10),D(B);
}
要求写出程序的输出结果,用序号标出输出顺序
但是我把这些代码打进VC++6.0里无法运行,加了头文件#include <string.h>还是无法运行
为什么? 展开
2个回答
展开全部
我成功运行了,有图有真相:
(VC++6.0编译、连接main.cpp)
#include <iostream.h>
#include <string.h>
class X{
int a; char *b; float c;
public:
X():b("X::X(1)"),a(3),c(10){
cout<<"a="<<a<<",b="<<b<<",c="<<c<<endl; }
X(int x1,char *x2,float x3):c(x3),a(x1){
b=new char[sizeof(x2)+1]; strcpy(b,x2);
cout<<"a="<<a<<",b="<<b<<",c="<<c<<endl; }
X(int x1,char*x2="X::X(2)",int x3=20):b(x2),c(x3),a(x1){
cout<<"a="<<a<<",b="<<b<<",c="<<c<<endl; }
X(X& other){
a=other.a+100; b="X::X(3)" ; c=other.c;
cout<<"a="<<a<<",b="<<b<<",c="<<c<<endl; } };
void main(){
X *A=new X(4,"X::X(4)",32);
X B,C(10),D(B);
}
你要记得保存成.cpp哦。如果不行,请粘贴一下报的错误是什么,或者出现了什么其它状况。
2013-07-15
展开全部
建议把#include<iostream.h>改成
#include <iostream>
using namespace std;
有的编译器会不认识iostream.h
#include <iostream>
using namespace std;
有的编译器会不认识iostream.h
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询