[英]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.