2016-07-17 38 views
-4

在下面的代码中,我试图访问参考数组的结构和移位它在数组索引中。
访问结构时发生invalid conversion from ‘int’ to ‘const char*’ [-fpermissive]错误,因为对索引的引用似乎被读为cstring的指示。 如何在此上下文中访问结构成员?哪里不对?修改int类型错误的结构成员:从'int'到'const char *'的无效转换[-fpermissive]

void removeSong (Song songList[], int& size){ 
    int indexRem; 
    int i; 
    cout << "Input index to remove" << endl; 
    cin >> indexRem; 

//Error checking for correct index(0 and 1 less than count) needed 

    for(i = indexRem; i < size; i++){ 
     songList[i] = songList[i+1]; 
    } 

    strcpy(songList[i].title, songList[i+1].title); 
    strcpy(songList[i].artist, songList[i+1].artist); 
    strcpy(songList[i].album, songList[i+1].album); 
    strcpy(songList[i].min, songList[i+1].min); 
    strcpy(songList[i].sec, songList[i+1].sec); 

    size--; 
} 

编辑:此问题与C字符串绘制不正确的关系。这个问题是不恰当的使用strcpy函数。

+0

至于错误,*你在哪里得到它,在哪一行?结构是什么样的? –

+0

为什么你根本无法使用'std :: vector '和另外'std :: string'而不是char数组? – PaulMcKenzie

+0

错误发生在'strcpy(songList [i] .min,songList [i + 1] .min); strcpy(songList [i] .sec,songList [i + 1] .sec);' – 0x1000001

回答

1

没有至少看到Song结构定义,我只能假设它至少有一个成员是int类型。 strcpy功能是只有 C字符串(const char*类型的变量)所必需的,所以如果您尝试将其用于int,则会出现错误。

+0

这就是答案。谢谢。 – 0x1000001

相关问题