请各位来看看,关于在C++ 里碰到的异常
请各位来看看,关于在C++ 里碰到的错误
刚碰C++, 错误很多,就是自己找不到。。。
但是出现了 很多错误:1:binary '>>' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' (or the
re is no acceptable conversion)
2:binary '<<' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' (or the
re is no acceptable conversion)
3:error C2057: expected constant expression
4:error C2466: cannot allocate an array of constant size 0
5:error C2133: 'student' : unknown size
请问,1:程序错在哪?
2:有没有其它方法来实现我的目的呢 ? (还要用到类)
拜托 大家了,刚入门,大家懂的。。
------解决方案--------------------
#include<string.h>改为#include<string>
people student[b];改为固定大小的数组或者用指针来动态开辟内存。
------解决方案--------------------
int a=2;
int arr[a];
是错误的,你翻了类似的错误
懂了吗
int a;
cin>>a;
int * p=new int[a];
for(int i=0;i <a ; i++)
*(p+i)=i+1;
delete []p;
刚碰C++, 错误很多,就是自己找不到。。。
- C/C++ code
#include<iostream> #include<string.h> using namespace std; class people { public: people() { } int num; string name; string addr; int age; bool sex; void input() { cout<<"请分别输入编号,姓名,家庭地址,年龄,性别(1为男0为女)。"<<endl; cin>>num>>name>>addr>>age>>sex; } void output() { cout<<"编号:"<<num<<"姓名:"<<name<<"家庭地址:"<<addr<<"年龄:"<<age<<"性别:"<<sex<<endl; } }; int main() { int b =1; cout<<"请输入人数"<<endl; cin>>b; people student[b]; int a ; for(a=0;a<b;a++) { student[a].input(); } for(a=0;a<b;a++) { student[a].output(); } return 0; }
但是出现了 很多错误:1:binary '>>' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' (or the
re is no acceptable conversion)
2:binary '<<' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' (or the
re is no acceptable conversion)
3:error C2057: expected constant expression
4:error C2466: cannot allocate an array of constant size 0
5:error C2133: 'student' : unknown size
请问,1:程序错在哪?
2:有没有其它方法来实现我的目的呢 ? (还要用到类)
拜托 大家了,刚入门,大家懂的。。
------解决方案--------------------
#include<string.h>改为#include<string>
people student[b];改为固定大小的数组或者用指针来动态开辟内存。
------解决方案--------------------
int a=2;
int arr[a];
是错误的,你翻了类似的错误
懂了吗
int a;
cin>>a;
int * p=new int[a];
for(int i=0;i <a ; i++)
*(p+i)=i+1;
delete []p;