c++中struct包含string数组出现的有关问题(C++编程思想习题)
c++中struct包含string数组出现的问题(C++编程思想习题)
c++编程思想书上说在struct中打印数组s时,会出现问题,但是并没有出现,不知道自己哪里错了,还望指教。

------解决思路----------------------
看不懂楼主说的那个问题,不过看代码是一点问题都没有啊,都是普通的字符串赋值打印而已
------解决思路----------------------
能有什么问题?
c++编程思想书上说在struct中打印数组s时,会出现问题,但是并没有出现,不知道自己哪里错了,还望指教。
#include<iostream>
#include<string>
using namespace std;
struct Lib{
string a;
string b;
string c;
string s[3];
};
class Libs{
string a;
string b;
string c;
string s[3];
public:
void setString(string a,string b,string c){
this->s[0]=a;
this->s[1]=b;
this->s[2]=c;
}
void seta(string a){this->a = a;}
void setb(string b){this->b = b;}
void setc(string c){this->c = c;}
string geta(){return a;}
string getb(){return b;}
string getc(){return c;}
string getString(int index){
if(index<0||index>2)
return NULL;
return s[index];
}
};
int main(){
Lib x;
x.a="a";
x.b="b";
x.c="c";
cout<<"struct(a,b,c):"<<x.a<<" "<<x.b<<" "<<x.c<<endl;
x.s[0]="a";
x.s[1]="b";
x.s[2]="c";
cout<<"struct_string(s):"<<x.s[0]<<" "<<x.s[1]<<" "<<x.s[2]<<endl;
Libs y;
y.seta("a");
y.setb("b");
y.setc("c");
y.setString("a","b","c");
cout<<"class(a,b,c):"<<y.geta()<<" "<<y.getb()<<" "<<y.getc()<<endl;
cout<<"class_string(s)"<<y.getString(0)<<" "<<y.getString(1)<<" "<<y.getString(2)<<endl;
return 0;
}
------解决思路----------------------
看不懂楼主说的那个问题,不过看代码是一点问题都没有啊,都是普通的字符串赋值打印而已
------解决思路----------------------
能有什么问题?