Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 字符串库的复制方法不';我不能在我的构造函数上工作_C++_Oop - Fatal编程技术网

C++ 字符串库的复制方法不';我不能在我的构造函数上工作

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

当我在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 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)您正在从填充的空字符串
团队
复制到参数
团队