C++ 字符串库的复制方法不';我不能在我的构造函数上工作
当我在main中调用display函数时,它不会输出初始化对象的字符串C++ 字符串库的复制方法不';我不能在我的构造函数上工作,c++,oop,C++,Oop,当我在main中调用display函数时,它不会输出初始化对象的字符串 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
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;
}
}
};
Grupa类{
字符指示;
弦乐队[4];
公众:
Grupa(字符索引,字符串组[4])
{
指示性=ind;
复制(团队,团队+4,团队);//这里没有正确复制字符串!
}
无效显示()
{
int i=0;
难道你的副本走错了方向:
class Grupa{
char indicativ;
string team[4];
public:
Grupa(char ind,string teams[4])
{
indicativ=ind;
std::copy(teams,teams+4,team);
// ^ destination
}
};
(1) .std::copy
是
的一部分,而不是
(2)您正在从填充的空字符串团队
复制到参数团队