当我在main中调用显示功能时,它不会输出我已初始化我的对象的字符串。
class Grupa{
char indicativ;
string team[4];
public:
Grupa(char ind,string teams[4])
{
indicativ=ind;
copy(team,team+4,teams);//here it doesn't copy the string correctly!
}
void display()
{
int i=0;
cout<<"Grupa "<<indicativ<<":"<<endl;
for(i=0;i<4;i++)
{
cout<<i+1<<". "<<team[i]<<endl;
}
}
};
答案 0 :(得分:2)
你的副本方向错误:
class Grupa{
char indicativ;
string team[4];
public:
Grupa(char ind,string teams[4])
{
indicativ=ind;
std::copy(teams,teams+4,team);
// ^ destination
}
};