2015-10-02 134 views
-3

所以我得到了上面提到的错误代码行: “women [count_wc] =(temp );” [错误]不能将'std :: string {aka std :: basic_string}'转换为赋值中的'char' - C++错误不能将'std :: string {aka std :: basic_string <char>}'转换为'char'的赋值 - C++

这是被调用的函数内部。

另外在函数实际被调用的地方发现了另一个错误。错误 “get_comp_women(women,MAX_W,array,ROW);” (std :: string *)(& women)'从'std :: string * {aka std :: basic_string *}'转换为'std :: string {aka std :: basic_string}'的错误代码为 [Error] “

const int MAX_W = 18; 
const int MAX_T = 18; 
const int MAX_E = 14; 
const int ROW = 89; 

using namespace std; 

struct data 
{ 
    string name; 
    string event; 
}; 


void get_comp_women(string women, int MAX_W, data array[], int ROW) 
{ 
    int count_wc = 0; 
    int count_wn = 0; 
    int event_occ = 0; 

    string temp; 

    temp = (array[0].name); 
    event_occ = (ROW + MAX_W); 


    for (int i = 1; i < event_occ; i++) 
    { 
     if (temp == array[count_wn].name) 
     { 
      women[count_wc] = (temp); 
      count_wn++; 
     } 
     else 
     { 
      temp = array[count_wn].name; 
      count_wc++; 
     } 
    } 

int main() 
{ 
    string women[MAX_W]; 
    data array[ROW]; 
    get_comp_women(women, MAX_W, array, ROW); 
} 
+2

我认为错误信息应该是不言自明的。阅读它们,并查看函数声明,以及在调用函数时通过的内容。 –

+0

你想要做什么'women [count_wc] =(temp);'? – MikeCAT

+0

将参数类型从'string women'改为'string women []'。 – owacoder

回答

2

你的函数接受womenstd::string,当你需要一个数组,所以,在函数内部women[count_wc]手段‘字符的字符串’,

women[count_wc] = (temp); 
\____________/ \____/ 
^    ^-----std::string 
    ^--- one character in the string 
不是‘字符串数组字符串’

您需要更改您的功能签名,以便它接受std::string[]而不是std::string

void get_comp_women(string women[], int MAX_W, data array[], int ROW) 

,你都拿到第二个错误是不言自明和手段正是这一点(尝试一个数组传入,正等待一个字符串的函数)。

+0

哇,你是对的,非常感谢。这个错误很简单。 –

0
void get_comp_women(string women, int MAX_W, data array[], int ROW) 

应该成为

void get_comp_women(string women[], int MAX_W, data array[], int ROW) 

功能的两个呼叫,并且在其内部的逻辑期望的阵列。

+0

欢呼的人,代码现在工作。 –

相关问题