简体   繁体   English

错误无法转换 &#39;std::string {aka std::basic_string<char> }&#39; 到 &#39;char&#39; 赋值 - C++

[英]Error cannot convert 'std::string {aka std::basic_string<char>}' to 'char' in assignment - C++

So i get the above mentioned error in the line of code: "women[count_wc] = (temp);"所以我在代码行中得到了上面提到的错误:“women[count_wc] = (temp);” [Error] cannot convert 'std::string {aka std::basic_string}' to 'char' in assignment - C++ [错误] 无法在赋值中将“std::string {aka std::basic_string}”转换为“char” - C++

which is inside the function being called.这是被调用的函数内部。

Also another error is found in the place where the function is actually being called.也是在该功能实际上是被称为地方发现了另一个错误。 the error at "get_comp_women(women, MAX_W, array, ROW);" “get_comp_women(women, MAX_W, array, ROW);”处的错误is [Error] could not convert '(std::string*)(& women)' from 'std::string* {aka std::basic_string*}' to 'std::string {aka std::basic_string}'是 [错误] 无法将 '(std::string*)(& women)' 从 'std::string* {aka std::basic_string*}' 转换为 'std::string {aka std::basic_string}'

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);
}

Your function accepts women as std::string , while you needed an array, so, inside the function women[count_wc] means "character in a string", not "string in an array of strings"您的函数接受women作为std::string ,而您需要一个数组,因此,在函数women[count_wc]表示“字符串中的字符”,而不是“字符串数组中的字符串”

women[count_wc] = (temp);
\____________/    \____/
   ^                 ^-----std::string   
   ^--- one character in the string

You need to change your function signature so it accepts std::string[] instead of std::string :您需要更改函数签名,使其接受std::string[]而不是std::string

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

The second error that you were getting is pretty self-explanatory and means exactly this (trying to pass an array into a function that awaits a string).你得到的第二个错误是不言自明的,意思就是这个(试图将一个数组传递给一个等待字符串的函数)。

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

should become应该成为

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

Both the call of the function and the logic inside it expect an array.函数的调用和其中的逻辑都需要一个数组。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误无法转换 'std::string {aka std::basic_string<char> }' 到 'int' 赋值</char> - Error cannot convert 'std::string {aka std::basic_string<char>}' to 'int' in assignment 错误无法转换 'std::string* {aka std::basic_string<char> *}' 到 'node*' 在分配</char> - Error cannot convert 'std::string* {aka std::basic_string<char>*}' to 'node*' in assignment 错误:无法转换 &#39;std::basic_string<char> &#39; 到 &#39;char&#39; 赋值 - error: cannot convert 'std::basic_string<char>' to 'char' in assignment 为什么我收到错误:无法转换 &#39;std::string {aka std::basic_string<char> }&#39; 到 &#39;char*&#39; 赋值? - Why am I getting error: cannot convert ‘std::string {aka std::basic_string<char>}’ to ‘char*’ in assignment? std :: string {aka std :: basic_string <char> 分配给&#39;&#39;&#39;char *&#39; - std::string {aka std::basic_string<char>}' to 'char*' in assignment| 错误:无法从&#39;std :: string * {aka std :: basic_string转换 <char> *}&#39;为&#39;std :: string {aka std :: basic_string <char> }&#39;| - error: could not convert from 'std::string* {aka std::basic_string<char>*}' to 'std::string {aka std::basic_string<char>}'| 错误:无法转换&#39;std :: basic_string <char> 从&#39;到&#39;int&#39;分配 - error: cannot convert ‘std::basic_string<char>’ to ‘int’ in assignment 错误:无法转换&#39;std :: string {aka std :: basic_string <char> 初始化时&#39;&#39;到&#39;char *&#39; - error: cannot convert ‘std::string {aka std::basic_string<char>}’ to ‘char*’ in initialization C ++错误:无法调用&#39;(std :: string {aka std :: basic_string <char> })(std :: string&)&#39; - C++ Error: no match for call to ‘(std::string {aka std::basic_string<char>}) (std::string&)’ C ++错误:无法转换&#39;std :: basic_string <char> &#39;至&#39;const char *&#39; - C++ error: cannot convert ‘std::basic_string<char>’ to ‘const char*’
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM