萌新求教 书里的程序 写出运行结果 我运行 结果报错
c++吧
全部回复
仅看楼主
level 13
狗gou富贵 楼主
#include <iostream>
using namespace std;
int n;
int *p1;
int fun(){
static int a;
int b;
cout<<"a="<<a<<",";
cout<<"b="<<b<<endl;
}
void main(){
int *p2;
int m;
fun(){
int n(10),m(20);
cout<<"n="<<n<<endl<<"m="<<m<<endl;
}
cout<<"n="<<n<<endl<<"m="<<m<<endl;
if(p1)
cout<<"p1="<<p1<<endl;
if(p2)
cout<<"p2="<<p2<<endl;
}
#include <iostream.h>
double f(int a=10,int b=20,int c=5){
return a*b*c;
}
void main(){
cout<<f()<<endl<<f(20)<<endl<<f(10,10)<<endl<<f(10,10,10)<<endl;
}
#include <iostream>
#include <memory>
using namespace std;
struct node{
int data;
shared_ptr<node>next;
};
void main(){
int a[]={3,4,1,8,9,2,7};
shared_ptr<node>list(new node),p;
list->data=0;
for(auto v:a){
shared_ptr<node>q(new node)
q->data = v;
p->next = q;
p = p-> next;
}
p->next=null;
p=list->next;
int s=0;
while(p){
cout<<p->data<<"\n";
s+=p->data;
p=p->next;
}
cout<<"\ns="<<s<<endl;
}
2018年03月22日 13点03分 1
level 13
狗gou富贵 楼主
dd
2018年03月22日 13点03分 2
level 9
发一下报错截图吧,不然不好说→_→
2018年03月22日 16点03分 3
第二个我搞出来了
2018年03月23日 13点03分
level 13
狗gou富贵 楼主
第一个
第三个直接死循环了
2018年03月23日 13点03分 5
level 13
狗gou富贵 楼主
#include <iostream>
#include <memory>
using namespace std;
int main(){
int i=10;
auto_ptr<int> ap1(new int(4)),ap2;
ap2=ap1;
cout<<*ap2;
cout<<*ap1<<endl;
char *c;
shared_ptr<char> sc;
sc=c;
sc=new char(10);
}
这个要怎么改
2018年03月23日 14点03分 6
好不容易写完,度娘抽风删帖
2018年03月23日 14点03分
level 10
第一个main函数里面不能嵌套函数,第三个智能指针没有开辟空间,第四个这样写:
int i = 10;
auto_ptr<int> ap1(new int(4)), ap2;
ap2 = ap1;
cout << *ap2;
cout << *ap1 << endl;
char *c;
c = new char(10);
shared_ptr<char> sc(c);
2018年03月23日 14点03分 9
哦哦 谢谢 我明天试试看
2018年03月23日 15点03分
level 1
怕不是一个学校的
2018年03月31日 17点03分 10
1